Home >Backend Development >C#.Net Tutorial >Easily process XML data in .NET Framework (3-2)
??ValidationType attribute sets the type of validation, it can be: DTD, XSD, XDR or none. If no validation type is specified (using the ValidationType.Auto option), the browser will automatically use the most appropriate validation type based on the document. Any error presented during the validation process will trigger the ValidationEventHandler event. If the event ValidationEventHandler event handler is not provided, an XML exception is thrown. Defining a ValidationEventHandler event handler is a way to catch any XML exceptions caused by errors in the XML source file. It's important to note that the browser's philosophy is to check that a document is well-formed and that it conforms to the schema. If a validated browser finds an XML document with serious format errors, it will only trigger an XmlException, and it will not trigger other events.
??Validation occurs when the user moves the pointer forward using the Read method. Once the node is parsed and read, it gets passed the internal object that handles the validation. Authentication control is based on the node type and the type of authentication being requested. It confirms whether all attributes of the node and the child nodes contained by the node meet the verification conditions.
??The verification object internally calls two different styles of tools: DTD analyzer and schema builder. The DTD parser looks at the contents of the current node and subtrees that do not conform to the DTD. The schema generator builds a SOM (schema object model) for the current node based on the XDR or XSD schema. The schema generator class is actually the base class for all designated XDR and XSD schema generators. Why? Although many similar methods of XDR and XSD architectures are processed, there is no difference in their performance during execution.
??If the node has child nodes, use another temporary browser to collect child node information, so the node's schema information can be completely verified. You can see Figure 5:
?? Note that although the structure function of the XmlValidatingReader class can receive an XmlReader class as its browser, the browser can only be an instance of the XmlTextReader class or its An instance of a derived class. This means that you cannot use other classes derived from XmlReader (such as a custom XML browser). Internally, the XmlValidatingReader class assumes that the browser is a child XmlTextReader object and explicitly converts the passed browser into an XmlTextReader class. If you use XmlNodeReader or a custom browser, the program will error during compilation and throw an exception at runtime.
??Node Browser
??XML browser provides an incremental method (reading one node one by one) to process the content of the document. So far, we have assumed that the source file is a disk-based stream or a string stream. However, we cannot guarantee that in practice an XMLDOM object of the source file will be provided to us. In this case, we need a special class with special read methods. For this situation, the .NET Framework provides the XmlNodeReader class.
??Just like XmlTextReader accesses all nodes in the specified XML stream, the XmlNodeReader class accesses all nodes in the XMLDOM subtree. The XMLDOM class (XmlDocument class in the .NET Framework) supports Xpath-based methods, such as the SelectNodes method and the SelectSingleNode method. The purpose of these methods is to place matching nodes in memory. If you need to process all nodes in a subtree, a node browser is more efficient than a browser that processes nodes incrementally:
// xmldomNode is the XML DOM node
XmlNodeReader nodeReader = new XmlNodeReader(xmldomNode ; First fill the data into the XMLDOM tree, and then use the XmlNodeReader class and the XMLDOM class to jointly process the data. It's also efficient.
The above is the content of easily processing XML data (3-2) in .NET Framework. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!