本文整理匯總了C#中System.Xml.XmlNodeReader.ReadEndElement方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlNodeReader.ReadEndElement方法的具體用法?C# XmlNodeReader.ReadEndElement怎麽用?C# XmlNodeReader.ReadEndElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlNodeReader
的用法示例。
在下文中一共展示了XmlNodeReader.ReadEndElement方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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;
}
示例2: ReadXml
//.........這裏部分代碼省略.........
}
// If diffgram, then read the first element as diffgram
if (reader.LocalName == "diffgram" && reader.NamespaceURI == XmlConstants.DiffgrNamespace) {
switch (mode) {
case XmlReadMode.Auto:
case XmlReadMode.IgnoreSchema:
case XmlReadMode.DiffGram:
XmlDiffLoader DiffLoader = new XmlDiffLoader (this);
DiffLoader.Load (reader);
if (mode == XmlReadMode.Auto)
result = XmlReadMode.DiffGram;
shouldReadData = false;
break;
case XmlReadMode.Fragment:
reader.Skip ();
break;
default:
reader.Skip ();
break;
}
}
// if schema after diffgram, just skip it.
if (!shouldReadData && reader.LocalName == "schema" && reader.NamespaceURI == XmlSchema.Namespace) {
shouldNotInfer = true;
switch (mode) {
default:
reader.Skip ();
break;
case XmlReadMode.ReadSchema:
case XmlReadMode.DiffGram:
if (Tables.Count == 0)
ReadXmlSchema (reader);
break;
}
}
if (reader.EOF)
return result == XmlReadMode.Auto ?
potentialDataSetName != null && !shouldNotInfer ?
XmlReadMode.InferSchema :
XmlReadMode.IgnoreSchema : result;
// Otherwise, read as dataset... but only when required.
if (shouldReadData && !shouldNotInfer) {
switch (mode) {
case XmlReadMode.Auto:
if (Tables.Count > 0)
goto case XmlReadMode.IgnoreSchema;
else
goto case XmlReadMode.InferSchema;
case XmlReadMode.InferSchema:
InferXmlSchema (doc, null);
if (mode == XmlReadMode.Auto)
result = XmlReadMode.InferSchema;
break;
case XmlReadMode.IgnoreSchema:
case XmlReadMode.Fragment:
case XmlReadMode.DiffGram:
break;
default:
shouldReadData = false;
break;
}
}
if (shouldReadData) {
XmlReader dataReader = reader;
if (doc != null) {
dataReader = new XmlNodeReader (doc);
dataReader.MoveToContent ();
}
if (reader.NodeType == XmlNodeType.Element)
XmlDataReader.ReadXml (this, dataReader,
mode);
}
if (skippedTopLevelElement) {
switch (result) {
case XmlReadMode.Auto:
case XmlReadMode.InferSchema:
// DataSetName = potentialDataSetName;
// result = XmlReadMode.InferSchema;
break;
}
if (reader.NodeType == XmlNodeType.EndElement)
reader.ReadEndElement ();
}
//*
while (input.Depth > depth)
input.Read ();
if (input.NodeType == XmlNodeType.EndElement)
input.Read ();
//*/
input.MoveToContent ();
return result == XmlReadMode.Auto ?
XmlReadMode.IgnoreSchema : result;
}