本文整理汇总了C#中System.IO.XmlReader.MoveToContent方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.MoveToContent方法的具体用法?C# XmlReader.MoveToContent怎么用?C# XmlReader.MoveToContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.XmlReader
的用法示例。
在下文中一共展示了XmlReader.MoveToContent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// Create a new <see cref="XElement"/> containing the contents of the
/// passed in <see cref="XmlReader"/>.
/// </summary>
/// <param name="reader">
/// An <see cref="XmlReader"/> containing the XML to be read into the new
/// <see cref="XElement"/>.
/// </param>
/// <param name="options">
/// A set of <see cref="LoadOptions"/>.
/// </param>
/// <returns>
/// A new <see cref="XElement"/> containing the contents of the passed
/// in <see cref="XmlReader"/>.
/// </returns>
public static XElement Load(XmlReader reader, LoadOptions options)
{
if (reader == null) throw new ArgumentNullException("reader");
if (reader.MoveToContent() != XmlNodeType.Element) throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ExpectedNodeType, XmlNodeType.Element, reader.NodeType));
XElement e = new XElement(reader, options);
reader.MoveToContent();
if (!reader.EOF) throw new InvalidOperationException(SR.InvalidOperation_ExpectedEndOfFile);
return e;
}
示例2: ReadElementFrom
/// <summary>
/// Generates a <see cref="XElement"/> from its XML respresentation.
/// </summary>
/// <param name="reader">
/// The <see cref="XmlReader"/> stream from which the <see cref="XElement"/>
/// is deserialized.
/// </param>
void IXmlSerializable.ReadXml(XmlReader reader)
{
if (reader == null) throw new ArgumentNullException("reader");
if (parent != null || annotations != null || content != null || lastAttr != null) throw new InvalidOperationException(SR.InvalidOperation_DeserializeInstance);
if (reader.MoveToContent() != XmlNodeType.Element) throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ExpectedNodeType, XmlNodeType.Element, reader.NodeType));
ReadElementFrom(reader, LoadOptions.None);
}