Easy XML data processing in. NETFramework (1-3)

Source: Internet
Author: User
?? The type of each node is one of the XmlNodeType enumeration. in the code shown in 3, we only use the two types: Element and EndElement. The output source code re-customizes the original document structure. is it discarded or neglected ?? The type of each node is one of the XmlNodeType enumeration. in the code shown in 3, we only use the two types: Element and EndElement. The output source code re-customizes the original document structure. it discards or ignores the attributes and node content of the XML element, and only outputs the element node name. Suppose we have applied the following XML snippet:

?? <Mags>
?? <Mag name = 'msdn Magazine'>
?? MSDN Magazine
?? </Mag>
?? <Mag name = 'msdn voices'>
?? MSDN Voices
?? </Mag>
?? </Mags>
?? The output result of the above program is as follows:

?? <Mags>
?? <Mag>
?? </Mag>
?? <Mag>
?? </Mag>
?? </Mags>

?? The subnode indentation is set based on the browser's Depth attribute (Depth attribute). The Depth attribute returns an integer that represents the nested hierarchy of the current node. All text is placed in the StringWriter object (a stream-based class that encapsulates the StrigBuilder class is very convenient ).

?? As mentioned above, the browser does not actively visit attribute nodes through the Read method. To visit the attribute node clustering of the current element, you must use a simple loop held by the return value of the MoveToNextAttribute method to traverse the aggregation. The following code visits all attributes of the current node and combines the attribute name and its value with a comma to form a string:
?? If (reader. HasAttributes)
?? While (reader. MoveToNextAttribute ())
?? Buf = reader. name' = \ ''reader. value '\',';
?? Reader. MoveToElement ();

?? When you complete attribute set processing, call the MoveToElement method to return the pointer to the element node to which the attribute belongs. To be accurate, the MoveToElement method is not a real moving pointer, because the pointer has never been removed from the element node when processing the attribute set. The MoveToElement method only points to an internal member and obtains the value of the member in sequence. For example, you can use the Name attribute to obtain the attribute Name of an attribute, and then call the MoveToElement method to move the pointer to the element node to which it belongs. However, when you do not need to constantly process other nodes, you do not have to call the MoveToElement method.


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.