/// <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; }
/// <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); }