Easily process XML data in. NETFramework (2-2)

Source: Internet
Author: User
Tags xml reader
?? String and Fragment ?? When programmers cut down the MSXML program, they will find a great difference between COM and. NETFrameworkXMLAPI .. The NETFramework class itself does not provide methods to analyze XML data stored in strings. Unlike MSXML analyzer ?? String and Fragment

?? When programmers cut down the MSXML program, they will find a great difference between COM and. NET Framework XML APIs .. NET Framework Class itself does not provide methods to analyze XML data stored in strings. Unlike MSXML analyzer objects, the XmlTestReader class does not provide any LoadXML method to create a browser from a well-structured character. The LoadXML method is not provided because you can use the special text reader --- StringReader class to achieve the same effect.

?? One of XmlTextReader's structure functions receives a TextReader derived object and an XML reader as parameters (this browser is created based on the content of text reader ). A text reader class is a stream, which is a natural character optimized. The StringReader class is a continuous TextReader class and uses a memory string as its input stream. The following code snippet demonstrates how to initialize an XML reader and use a well-structured XML string as its input:

?? String xmlText = '...';

?? StringReader strReader = new StringReader (xmlText );

?? XmlTextReader reader = new XmlTextReader (strReader );



?? In addition, use the StringWriter class to replace the TextWrite class. you can create an XML document from memory characters.

?? A specified type of XML string is a fragment. XML segment composed of XML text, but XML documents without root nodes are not XML documents with good structure, so they cannot be used. An XML segment is part of the original document, so it may lack the root node. For example, the following XML text is a valid XML segment, but it is not a valid XML document because it does not have a root node:

?? Dino

?? Esposito

??. The. NET Framework xml api allows programmers to combine XML fragments with the content of a Analyzer. the analyzer content consists of a file similar to the encoding character set, DTD document, namespace, language, and space handler:

?? Public XmlTextReader (

?? String xmlFragment,

?? XmlNodeType fragType,

?? XmlParserContext context

??);

?? The xmlFragment parameter contains XML string analysis. The FragType parameter represents the fragment type, which gives the type of the fragment root node. Only nodes of the element, attivity, and document types can serve as the root node of fragment. the contents of the analyzer can be described by the XmlParserContext class.


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.