Provides access to the root element of this document.
[Visual Basic] Public Property Root As XmlElement [C#] public XmlElement Root {get; set;} [C++] public: __property XmlElement* get_Root(); public: __property void set_Root(XmlElement*); [JScript] public function get Root() : XmlElement; public function set Root(XmlElement);
Exception Type | Condition |
---|---|
ArgumentException | When assigning an element that does not belong to the same XML context as this document. |
When the Root property is read, the value returned is the first child node of type XmlElement in the document, or null if the document has no XmlElement child nodes.
When the Root property is written, the new element replaces the existing root element. If there is no existing root element, the new element is simply added to the child list.
To add a root element to a document that doesn't have one, call the AddElement method.
XmlDocument Class | XmlDocument Members | System.Xml Namespace