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

Source: Internet
Author: User
?? The ValidationType property sets the type of validation, which can be: DTD, XSD, XDR, or none. If the type of validation is not specified (with the ValidationType.Auto option), the browser will proactively use the most appropriate authentication type for the document. Any errors that are rendered during the validation process will trigger the ValidationEventHandler event. If the event ValidationEventHandler event handler is not supplied, an XML exception is thrown. Defining a ValidationEventHandler event handler is a way to catch any XML exception that is thrown in an XML source file that has an error. Keep in mind that the browser principle is to check whether a document is well-formed, and to check whether the document matches the schema. If a validated browser invents an XML document with a serious pattern error, it will only trigger the XmlException exception, and it will not trigger other events.

?? Validation occurs when the user moves the pointer forward with the Read method, and once the node is parsed and read, it gets the internal object that is passed over for processing validation. The validation control is based on the type of node and the type of authentication requested. It confirms that all the properties of the node and the child nodes contained in the node meet the validation criteria.

?? The validation object calls internally two objects of different styles: the DTD parser and the schema builder. The DTD parser should have the contents of the former node and sub-trees that do not conform to the DTD. The Schema Builder builds a SOM (schema object model) on the current node based on the XDR or XSD schema. The schema-born class is actually the base class for all of the XDR and XSD schema-based classes that are specified. Why, while many of the same methods of XDR and XSD schemas are processed, there is no difference in performance when they are fulfilled.

?? If the node has child nodes, it collects the child node information with another temporary browser, so the schema information of the node can be completely verified. You can look at figure V:



?? Be aware that although the struct function of the XmlValidatingReader class can receive a XmlReader class as its browser, the browser can only be an instance of the XmlTextReader class or an instance of one of its derived classes. This means that you cannot use other classes derived from XmlReader (such as a custom XML browser). Inside the XmlValidatingReader class, it assumes that the browser is a sub-XmlTextReader object and explicitly converts the passed-in browser to the XmlTextReader class. If you use XmlNodeReader or a custom browser, the program will compile with an error and throw an exception at run time.


?? Node browser

?? The XML browser provides an incremental method (read by one node) to process the contents of the document. So far, we have assumed that the source file is a hard disk-based stream or a string stream, however, we cannot guarantee that a source file will be supplied to us in the actual Xmldom object. In this case, we need a special class with a special reading method. In this case, the. NET Framework supplies the XmlNodeReader class.

?? Just like XmlTextReader visits all nodes in the specified XML stream, the XmlNodeReader class visits all nodes of the XMLDOM subtree. The Xmldom class (The XmlDocument class in the. NET framework) supports XPath-based methods, such as selectnodes methods and selectSingleNode methods. The purpose of these methods is to put the matching nodes in memory. If you need to deal with all the nodes in the subtree, the node browser is more efficient than the incremental approach to processing the nodes ' browsing:

XMLDOMNode is the XML DOM node

XmlNodeReader Nodereader = new XmlNodeReader (XMLDOMNode);

while (Nodereader.read ())

{

Do something here

}

?? When you want to reference custom data in a configuration file, such as a web.cofig file, populate the XMLDOM tree with this data, and then use the XmlNodeReader class with the XMLDOM class to process the data together. It's also efficient.


The above is the easy processing of XML data (3-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.