Xmldocument
Namespace:System. xml
Constructor
1. xmldocument () has no parameter constructor and creates an XML structure.
2. xmldocument (xmlimplementation)ParametersXmlimplementationI do not understand.
3. xmldocument (xmlnametable)ParametersXmlnametable
Example(Problem: load (string), absolute path, relative path cannot be enough) Solution: Load starts from the root directory.
Xmldocument xmldoc = New Xmldocument ();
// Bookstore. XML is the path of the XML file
Xmldoc. Load ( " Bookstore. xml " );
Attribute
Attributes obtains the value of attributecollection. to read the value of a node, node. attributes [nodename]
Childnodes
Baseuri: Get the URL of the current XML (absolute path)
Documentelement indicates the root of the XML document treeXmlelement. If no root exists, a null reference is returned.
The difference between childnodes and childnodes is that childnodes is accessed from the preface, and documentelement is accessed from the root node.
Code
Xmldocument Doc = New Xmldocument ();
Doc. Load ( " XML \ bookstore. xml " );
// Get Root Node
Xmlelement = Doc. documentelement;
String Content = Xmlelement. outerxml;
DocumenttypeWhat is the main function?
FirstchildThe first subset. If there is a preface, it starts from the preface.
Whether haschildnodes has subnodes
Nextsibling is next to the next node. If no node exists, null is returned.
Parentnode obtains the parent node of the node.
Prefix: If two nodes with the same name appear in an XML document, the namespace is used to differentiate the two nodes.
Code
<? XML version = " 1.0 " Encoding = " Gb2312 " ?> // The namespace F is defined. Because the XML uses the predefined meaning, an error will be reported if the element with the same element name appears in the same document.
< F: bookstore xmlns: F = " Http://www.w3school.com.cn/furniture " >
< F: Book Genre = " Fantasy " ISBN = " 2-3631-4 " >
< F: Title > Travel float </ F: Title >
< F: Author > Steve </ F: Author >
< F: Price > 5.95 </ F: Price >
</ F: Book >
< F: bookname >
< F: Title > New name </ F: Title >
</ F: bookname >
</ F: bookstore >
Preservewhitespace: whether to retain white space. True indicates that white space is retained. False indicates that white space is not retained. The default value is false.
PreviussiblingPrevious Node
Reference:
Http://kb.cnblogs.com/page/42226/