How to Use the XML architecture set
This example illustrates how to use the xmlschemacollection class used by xmlvalidatingreader for effective data verification. The xmlschemacollection class allows you to maintain the cache of multiple XML schema definition languages (XSD) and XML data simplified (XDR) architectures, which can be used when architecture is needed in the future. Although this class can store both the XSD and XDR architectures, only the XSD Schema can be applied to methods or attributes that use or return XMLSCHEMA.
The schema in xmlschemacollection can be used to verify XML data. When reading XML data, you can use xmlvalidatingreader to apply the verification. For information about how to use xmlvalidatingreader, see how to apply verification when reading XML.
Validation is the process of forcibly applying rules to XML content through document type definition (DTD) or a schema. Simply put, the architecture is the XML Representation of DTD, but it can also export the relationship between XML data and type information. The xmlvalidatingreader class provides verification support on xmltextreader.
|
VB schemacollection. aspx |
[Running example] | [View Source code] |
This example shows how xmlvalidatingreader uses xmlschemacollection for valid data verification. For the schema set, this example adds the XSD Schema xmlsc. XSD for verification. In this example, create an xmlvalidatingreader and add the schema from the schema set to the reader. Finally, this example uses the reader to read data and set the output display format.
... xmlvalidatingreader reader = NULL; xmlschemacollection xsc = new xmlschemacollection (); try {xsc. add (ARGs [1], new xmltextreader (ARGs [1]); reader = new xmlvalidatingreader (New xmltextreader (ARGs [0]); reader. schemas. add (xsc); reader. validationtype = validationtype. schema; while (reader. read ()){...}}
... Dim reader as xmlvalidatingreader dim xsc as xmlschemacollection = new xmlschemacollection () Try xsc. add (ARGs (1), new xmltextreader (ARGs (1) reader = new xmlvalidatingreader (New xmltextreader (ARGs (0) reader. schemas. add (xsc) reader. validationtype = validationtype. schema while (reader. read ())... end while... end try
|
C # |
VB |
|
Summary
- You can use xmlschemacollection as the cache for the pre-loaded architecture.
- These pre-loaded architectures only need to be loaded once and can be reused. In this way, higher analysis performance can be achieved.
- Xmlschemacollection supports both XDR and XSD architectures.