本文整理汇总了C#中System.Xml.XmlNodeReader.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNodeReader.Skip方法的具体用法?C# XmlNodeReader.Skip怎么用?C# XmlNodeReader.Skip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlNodeReader
的用法示例。
在下文中一共展示了XmlNodeReader.Skip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadXml
// LAMESPEC: XmlReadMode.Fragment is far from presisely
// documented. MS.NET infers schema against this mode.
public XmlReadMode ReadXml (XmlReader input, XmlReadMode mode)
{
switch (input.ReadState) {
case ReadState.EndOfFile:
case ReadState.Error:
case ReadState.Closed:
return mode;
}
// Skip XML declaration and prolog
input.MoveToContent ();
if (input.EOF)
return mode;
// FIXME: We need more decent code here, but for now
// I don't know the precise MS.NET behavior, I just
// delegate to specific read process.
switch (mode) {
case XmlReadMode.IgnoreSchema:
return ReadXmlIgnoreSchema (input, mode, true);
case XmlReadMode.ReadSchema:
return ReadXmlReadSchema (input, mode, true);
}
// remaining modes are: Auto, InferSchema, Fragment, Diffgram
XmlReader reader = input;
int depth = reader.Depth;
XmlReadMode result = mode;
bool skippedTopLevelElement = false;
string potentialDataSetName = null;
XmlDocument doc = null;
bool shouldReadData = mode != XmlReadMode.DiffGram;
bool shouldNotInfer = Tables.Count > 0;
switch (mode) {
case XmlReadMode.Auto:
case XmlReadMode.InferSchema:
doc = new XmlDocument ();
do {
doc.AppendChild (doc.ReadNode (reader));
} while (!reader.EOF &&
doc.DocumentElement == null);
reader = new XmlNodeReader (doc);
reader.MoveToContent ();
break;
case XmlReadMode.DiffGram:
if (!(reader.LocalName == "diffgram" &&
reader.NamespaceURI == XmlConstants.DiffgrNamespace))
goto case XmlReadMode.Auto;
break;
}
switch (mode) {
case XmlReadMode.Auto:
case XmlReadMode.InferSchema:
case XmlReadMode.ReadSchema:
if (!(reader.LocalName == "diffgram" &&
reader.NamespaceURI == XmlConstants.DiffgrNamespace) &&
!(reader.LocalName == "schema" &&
reader.NamespaceURI == XmlSchema.Namespace))
potentialDataSetName = reader.LocalName;
goto default;
case XmlReadMode.Fragment:
break;
default:
if (!(reader.LocalName == "diffgram" &&
reader.NamespaceURI == XmlConstants.DiffgrNamespace) &&
!(reader.LocalName == "schema" &&
reader.NamespaceURI == XmlSchema.Namespace)) {
if (!reader.IsEmptyElement) {
reader.Read ();
reader.MoveToContent ();
skippedTopLevelElement = true;
}
else {
switch (mode) {
case XmlReadMode.Auto:
case XmlReadMode.InferSchema:
DataSetName = reader.LocalName;
break;
}
reader.Read ();
}
}
break;
}
// If schema, then read the first element as schema
if (reader.LocalName == "schema" && reader.NamespaceURI == XmlSchema.Namespace) {
shouldNotInfer = true;
switch (mode) {
case XmlReadMode.IgnoreSchema:
case XmlReadMode.InferSchema:
reader.Skip ();
break;
case XmlReadMode.Fragment:
ReadXmlSchema (reader);
break;
//.........这里部分代码省略.........
示例2: convertFromXml
/// <summary>
/// Removing this from the IXmlSerializable Implementation because engineers keep exposing the SerialzableDictionary object
/// and that cannot be allowed because nobody else can deserialize. It is for persistance only so the logic was moved here.
/// </summary>
/// <param name="doc">The doc.</param>
/// <returns></returns>
private IList<string> convertFromXml(XmlDocument doc)
{
XmlReader reader = new XmlNodeReader(doc);
//First check empty element and return if found
bool wasEmpty = reader.IsEmptyElement;
reader.Read();
if (wasEmpty)
return null;
IList<string> result = new List<string>();
reader.ReadStartElement(DocumentElement);
if (reader.NodeType != XmlNodeType.Element)
return result;
//Loop through the nodes representing this object in the reader
while (reader.NodeType != XmlNodeType.EndElement)
{
//First try the optimized format
//string key = reader.GetAttribute(KEY_ATTRIBUTE);
string typeName = reader.GetAttribute(TYPE_ATTRIBUTE);
//Read the Xml element representing a new key & value pair
reader.ReadStartElement(ITEM_ELEMENT);
//if (String.IsNullOrEmpty(key))
//{
// //Key is not being stoed as an attribute - this must be xml in the old format
// //KEEP THIS CODE FOR BACKWARDS COMPATIBILITY
// //First we need to get the type of the object written to the Xml during serialization so that
// //we can create a new serializer that understands how to deserialize this type.
// typeName = reader.GetAttribute(TYPE_ATTRIBUTE);
// //Read the Xml element representing the key in this key & value pair
// reader.ReadStartElement(KEY_ELEMENT);
// //Allright now create the serializer and deserialize the defined object type
// XmlSerializer keySerializer = new XmlSerializer(typeof(string));
// //key = (string)keySerializer.Deserialize(reader);
// if (key == null)
// throw new ApplicationException(String.Format("Null key encountered on line {0}",
// reader.Depth));
// //Read the end of the key element
// reader.ReadEndElement();
//}
Type valuetype = (typeName != null ? Type.GetType(typeName) : typeof(object)) ?? typeof(object);
//Read the Xml element representing the value in this key & value pair
reader.ReadStartElement(VALUE_ELEMENT);
//Now create the serialize and deserialize the object type defined from the type attribute
XmlSerializer valueSerializer = new XmlSerializer(valuetype);
//HACK!!!
//Make sure you catch any errors caused by invalid types cannot be deserialized. For example this whole process
//kept blowing up because the type ould not be serialized.
string value;// = (TValue) valueSerializer.Deserialize(reader);
try { value = (string)valueSerializer.Deserialize(reader); }
catch (Exception)
{
value = default(string);
//skip top the end of the current element
reader.Skip();
}
//Read the end of the value element
reader.ReadEndElement();
//Now add the deserialized objects to the hashtable.
result.Add(value);
//Read the end of the element holding the key and value elements
if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == ITEM_ELEMENT)
reader.ReadEndElement();
reader.MoveToContent();
}
//All done - read the ending element
reader.ReadEndElement();
return result;
}
示例3: ParseAndSendMessages
/// <summary>
/// Parses an IM log file and sends the information to GDS
/// </summary>
/// <param name="logFile">The IM conversations log file</param>
/// <param name="lastIndexed">messages older than this will not be sent to GDS</param>
private void ParseAndSendMessages(string logFile, DateTime lastIndexed)
{
XmlDocument doc = new XmlDocument();
doc.Load(logFile);
XmlNodeReader reader = new XmlNodeReader(doc);
// reset user and buddy name
userName = null;
buddyName = null;
// Moves the reader to the root element.
reader.MoveToContent();
// move to the first message
reader.Read();
while(reader.LocalName == "Message")
{
// check the date of the message - if older skip
reader.MoveToAttribute("DateTime");
DateTime messageDateTime = DateTime.Parse(reader.Value);
reader.MoveToElement();
// if older than the last indexing time, skip the message
if (messageDateTime.CompareTo(lastIndexed) <= 0)
{
reader.Skip();
continue;
}
// get message data
MSNMessageData messageData = ParseMessageData(reader.ReadOuterXml());
// send this message to GDS for indexing
SendMessageData(messageData);
}
}