XML learning notes (2)

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.