Easy processing of XML data in the. NET Framework (2-2)

Source: Internet
Author: User
Tags xml reader
?? String and Fragment

?? The programmer cut down the program in MSXML and would invent a big difference between the COM and. NET Framework XML APIs. The. NET Framework class itself has no provisioning method to parse the XML data stored in the string. Unlike the MSXML parser object, the Xmltestreader class does not provide any kind of loadxml method to create a browser from a well-formed character. There is no way to supply similar loadxml because you can use special text reader---StringReader class to achieve the same effect.

?? XmlTextReader one of the struct functions receives a TextReader derived object and an XML reader as a parameter (the browser is based on the content of text reader). A text reader class is a stream, which is a stream of characters that are optimized by nature. The StringReader class continues the TextReader class and uses an in-memory string as its input stream. The following code snippet demonstrates how to initialize an XML reader with a well-formed XML string as its input:

?? String xmlText = ' ... ';

?? StringReader strreader = new StringReader (xmlText);

?? XmlTextReader reader = new XmlTextReader (Strreader);



?? In addition, using the StringWriter class instead of the Textwrite class, you can create an XML document from a memory character.

?? An XML string of the specified type is an XML fragment (fragment). XML fragments are made of XML text, but XML documents without root nodes are not well-formed XML documents and therefore cannot be exploited. An XML fragment is part of the original document, so it may lack a root node. For example, the following XML literal is a valid XML fragment, but not a valid XML document because it does not have a root node:

?? Dino

?? Esposito

??. The NET Framework XML API promises programmers to combine XML fragments with an analyzer content, which consists of a similar encoding character set, DTD document, namespace, language, and whitespace handlers:

?? Public XmlTextReader (

?? String XmlFragment,

?? XmlNodeType Fragtype,

?? XmlParserContext context

??);

?? The xmlfragment parameter contains XML string parsing. The Fragtype parameter shows the type of fragment, which gives the type of the fragment root node. Only Element,attibute and document types of node talent as the root node of fragment, the parser's content talent is XmlParserContext class description.


Reprint please indicate source: Easy processing of XML data in the. NET Framework (2-2)

The above is the easy processing of XML data (2-2) in the. NET framework, and more about topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.