Xmlreadersettings is an important class used to verify XML data. We will use this class to verify the XML file later. Here we will first demonstrate how to use xmlreadersettings to configure the attributes of the xmlreader output xmlreadersettings class.
Name |
Description |
Checkcharacters |
Gets or sets a value indicating whether to perform a character check. |
Closeinput |
Gets or sets a value that indicates whether the basic stream or textreader should be disabled when the reader is disabled. |
Conformancelevel |
Gets or sets the level of consistency that xmlreader will follow. |
Ignorecomments |
Gets or sets a value indicating whether to ignore comments. |
Ignoreprocessinginstructions |
Gets or sets a value indicating whether to ignore the processing command. |
Ignorewhitespace |
Gets or sets a value indicating whether to ignore insignificant white spaces. |
Linenumberoffset |
Get or setXmlreaderThe row number offset of the object. |
Linepositionoffset |
Get or setXmlreaderThe row position offset of the object. |
Nametable |
Gets or sets the xmlnametable used for atomic string comparison. |
Prohibitdtd |
Gets or sets a value indicating whether to disable document type definition (DTD) processing. |
Schemas |
Gets or sets the xmlschemaset used for schema verification. |
Validationflags |
Gets or sets a value indicating the schema verification settings. This setting is applied to verify the architectureXmlreaderObject (the validationtype attribute is setValidationtype. Schema). |
Validationtype |
Gets or sets a value, which indicatesXmlreaderWhether to perform verification or type allocation during reading. |
Xmlresolver |
Set xmlresolver for accessing external documents. |
Instance:
Protected Void Page_load ( Object Sender, eventargs E)
{
String Xmlfilepath = Request. physicalapplicationpath + @" \ Employees. xml " ;
Xmlreadersettings settings = New Xmlreadersettings ();
Settings. ignorecomments = True ;
Settings. ignorecomments = True ;
Try
{
Using (Xmlreader Reader = Xmlreader. Create (xmlfilepath, settings ))
{
String Result;
While (Reader. Read ())
{
If (Reader. nodetype = Xmlnodetype. element)
{
Result = "" ;
For ( Int Count = 0 ; Count < Reader. depth; count ++ )
{
Result+ = "---";
}
Result + = " -> " + Reader. Name + " <Br/> " ;
This . Memployeeslabel. Text + = Result;
}
}
}
}
Catch (Exception ex)
{
This. Memployeeslabel. Text= "An exception occured:" +Ex. message;
}
}
-> employees
----> employee
-------> name
----------> firstname
----------> lastname
-------> city
-------> state
-------> zipcode
----> employee
-------> name
----------> firstname
----------> lastname
-------> city
-------> state
-------> zipcode