ASP. NET 2.0 XML series (4): xmlreader class Introduction

Source: Internet
Author: User

 

(This article is from msdn)

Xmlreader is an abstract base class that provides non-Cache and read-only access to XML data. This class complies with the W3C Extensible Markup Language (XML) 1.0 and XML namespace recommendations.

Xmlreader supports reading XML data from streams or files. The methods and attributes defined by this class allow you to browse data and read the content of the node. The current node refers to the node where the reader is located. Use any read methods and attributes that return the current node value to promote the reader.

Xmlreader class allows you:

    • Check whether the characters are valid xml characters, and whether the element and attribute names are valid XML names.

    • Check whether the XML document format is correct.

    • Validate data according to the DTD or architecture.

    • Retrieve data from an XML Stream or skip unnecessary records using the extraction model.

Before using xmlreader to read XML documents, we need to know the attributes and methods of this class and the types of the node xmlnode.

1. attributes of the xmlreader class


Name Description
Attributecount When a derived class is overwritten, the number of attributes on the current node is obtained.
Baseuri When a derived class is overwritten, the base URI of the current node is obtained.
Canreadbinarycontent Gets a value indicating whether xmlreader can read binary data.
Canreadvaluechunk Gets a value that indicatesXmlreaderWhether to implement the readvaluechunk method.
Canresolveentity Gets a value that indicates whether the reader can analyze and parse entities.
Depth When a derived class is overwritten, the depth of the current node in the XML document is obtained.
EOF Gets a value that indicates whether the reader is positioned at the end of the stream when it is overwritten in a derived class.
Hasattributes Gets a value indicating whether the current node has any attributes.
Hasvalue When a derived class is overwritten, a value is obtained, which indicates whether the current node can have a value.
Isdefault When a derived class is overwritten, a value is obtained to indicate whether the current node is an attribute generated from the default value defined in The DTD or architecture.
Isemptyelement Gets a value that indicates whether the current node is a null element (for example<Myelement/>).
Item Overloaded. Obtain the value of this attribute when it is overwritten in a derived class.
Localname When a derived class is overwritten, obtain the local name of the current node.
Name When it is overwritten in a derived class, get the qualified name of the current node.
Namespaceuri When a derived class is overwritten, retrieve the namespace URI of the node on which the reader locates (in the form defined in W3C namespace specifications ).
Nametable When a derived class is overwritten, The xmlnametable associated with the implementation is obtained.
Nodetype When a derived class is overwritten, the type of the current node is obtained.
Prefix When a derived class is overwritten, The namespace prefix associated with the current node is obtained.
Quotechar When a derived class is overwritten, the quotation mark character used to enclose the attribute node value is obtained.
Readstate Gets the reader status when it is overwritten in a derived class.
Schemainfo Obtain the schema information allocated to the current node as the schema verification result.
Settings ObtainXmlreaderThe xmlreadersettings object of the instance.
Value When a derived class is overwritten, the text value of the current node is obtained.
Valuetype Obtain the Common Language Runtime Library (CLR) Type of the current node.
Xmllang Obtain the currentXML: LangRange.
Xmlspace Obtain the currentXML: SpaceRange.

 

2. xmlreader Class Method

 

Name Description
Close When it is overwritten in a derived class, change readstateClosed.
Create Overloaded. Create a new xmlreader instance.
Equals Overloaded. Determine whether the two object instances are equal. (Inherit from object .)
Getattribute Overloaded. When a derived class is overwritten, the attribute value is obtained.
Gethashcode Used as a hash function of a specific type. Gethashcode is suitableAlgorithmAnd data structures (such as hash tables. (Inherit from object .)
GetType Obtain the type of the current instance. (Inherit from object .)
Isname Gets a value that indicates whether the string parameter is a valid XML name.
Isnametoken Gets a value that indicates whether the string parameter is a valid XML name tag.
Isstartelement Overloaded. Test whether the current content node is a start tag.
Lookupnamespace When it is overwritten in a derived class, the namespace prefix is resolved within the range of the current element.
Movetoattribute Overloaded. When it is overwritten in a derived class, it is moved to the specified attribute.
Movetocontent Check whether the current node is content (non-blank text,CDATA,Element,Endelement,EntityreferenceOrEndentity. If this node is not a content node, the reader jumps forward to the next content node or the end of the file. It skips the following types of nodes:Processinginstruction,Documenttype,Comment,WhitespaceOrSignificantwhitespace.
Movetoelement When it is overwritten in a derived class, it is moved to an element that contains the current attribute node.
Movetofirstattribute When it is overwritten in a derived class, it is moved to the first attribute.
Movetonextattribute When it is overwritten in a derived class, it is moved to the next attribute.
Read When a derived class is overwritten, the next node is read from the stream.
Readattributevalue When a derived class is overwritten, the attribute value is parsed into one or moreText,EntityreferenceOrEndentityNode.
Readcontentas Read the content as an object of the specified type.
Readcontentasbase64 Read the content and return the base64 decoded binary bytes.
Readcontentasbinhex Read content and returnBinhexThe decoded binary bytes.
Readcontentasboolean Use the text content of the current locationBooleanRead.
Readcontentasdatetime Reads the text content of the current position as a datetime object.
Readcontentasdecimal Read the text content of the current location as a decimal object.
Readcontentasdouble Read the text content at the current position as a double-precision floating point number.
Readcontentasfloat Read the text content at the current position as a single-precision floating point number.
Readcontentasint Read the text content of the current position as a 32-bit signed integer.
Readcontentaslong Read the text content of the current position as a 64-bit signed integer.
Readcontentasobject Use the text content of the current locationObjectRead.
Readcontentasstring Read the text content of the current position as a string object.
Readelementcontentas Overloaded. Read the current element and return the content as an object of the specified type.
Readelementcontentasbase64 Read the element andBase64Decode the content.
Readelementcontentasbinhex Read the element andBinhexDecode the content.
Readelementcontentasboolean Overloaded. Read the current element value as a Boolean object.
Readelementcontentasdatetime Overloaded. Read the current element and use the contentDatetimeObject.
Readelementcontentasdecimal Overloaded. Use the current element valueDecimalObject reading.
Readelementcontentasdouble Overloaded. Read the current element and return the content as a double-precision floating point number.
Readelementcontentasfloat Overloaded. Read the current element value as a single-precision floating point number.
Readelementcontentasint Overloaded. Read the current element and return the content as a 32-bit signed integer.
Readelementcontentaslong Overloaded. Read the current element and return the content as a 64-bit signed integer.
Readelementcontentasobject Overloaded. Read the current element and use the contentObject.
Readelementcontentasstring Overloaded. Read the current element and use the contentStringObject.
Readelementstring Overloaded. This is a helper Method for reading simple plain text elements.
Readendelement Check whether the current content node is the end mark and push the reader to the next node.
Readinnerxml When a derived class is overwritten, all content (including tags) is read as strings.
Readouterxml When a derived class is overwritten, read indicates the node and all its sub-level content (including tags ).
Readstartelement Overloaded. Check whether the current node is an element and push the reader to the next node.
Readstring When a derived class is overwritten, the content of the element or text node is read as a string.
Readsubtree Returns the newXmlreaderInstance, which can be used to read the current node and all its subnodes.
Readtodescendant Overloaded. LetXmlreaderForward to the next matched child element.
Readtofollowing Overloaded. Read until the named element is found.
Readtonextsibling Overloaded. LetXmlreaderForward to the next matched peer element.
Readvaluechunk Read a large number of text streams embedded in XML documents.
Referenceequals Determine the specifiedObjectWhether the instance is the same. (Inherit from object .)
Resolveentity When it is overwritten in a derived classEntityreferenceObject reference of a node.
Skip Skip the sublevel of the current node.
Tostring Returns the currentObjectOfString. (Inherit from object .)

 

3. xmlnodetype enumeration member

 


Member name Description
Attribute Properties (for example,Id = '000000').AttributeA node can have the following subnode types:TextAndEntityreference.AttributeA node does not appear as a subnode of any other node type. Do not treat itElement.
CDATA CDATA section (for example,<! [CDATA [My escaped text]>). The CDATA section is used to escape text blocks that will be recognized as tags.CDATAA node cannot have any subnodes. It can useDocumentfragment,EntityreferenceAndElementNode sublevel.
Comment Annotations (for example,<! -- My comment -->).CommentA node cannot have any subnodes. It can useDocument,Documentfragment,ElementAndEntityreferenceNode sublevel.
Document The document object that serves as the root of the document tree provides access to the entire XML document.DocumentA node can have the following subnode types:Xmldeclaration,Element(Up to one ),Processinginstruction,CommentAndDocumenttype. It cannot appear in any node type sublevel.
Documentfragment Document snippets.DocumentfragmentA node associates a node or subtree with a document and is not actually included in this document.DocumentfragmentA node can have the following subnode types:Element,Processinginstruction,Comment,Text,CDATAAndEntityreference. It cannot appear in any node type sublevel.
Documenttype The document type declaration indicated by the following mark (for example,<! Doctype...>).DocumenttypeA node can have the following subnode types:NotationAndEntity. It can useDocumentNode sublevel.
Element Element (for example,<Item>).ElementA node can have the following subnode types:Element,Text,Comment,Processinginstruction,CDATAAndEntityreference. It can beDocument,Documentfragment,EntityreferenceAndElementThe child level of the node.
Endelement End Element tag (for example,</Item>). When xmlreader reaches the end of an elementEndelementNode.
Endentity Because resolveentity is calledXmlreaderReturn when the end of object replacement is reached.
Entity Entity declaration (for example,<! Entity...>).EntityNodes can have child nodes that indicate expanded entities (for exampleTextAndEntityreferenceNode ). It can useDocumenttypeNode sublevel.
Entityreference Entity reference (for example,& Num;).EntityreferenceA node can have the following subnode types:Element,Processinginstruction,Comment,Text,CDATAAndEntityreference. It can useAttribute,Documentfragment,ElementAndEntityreferenceNode sublevel.
None If notReadMethodXmlreader.
Notation Representation in document type declaration (for example,<! Notation...>).NotationA node cannot have any subnode. It can useDocumenttypeNode sublevel.
Processinginstruction Processing commands (for example,<? Pi test?>).ProcessinginstructionA node cannot have any subnode. It can useDocument,Documentfragment,ElementAndEntityreferenceNode sublevel.
Significantwhitespace Blank orXML: Space = "preserve"Blank in the range.
Text The text content of the node.TextA node cannot have any subnode. It can useAttribute,Documentfragment,ElementAndEntityreferenceThe child node of the node.
Whitespace Blank between tags.
Xmldeclaration XML declaration (for example,<? XML version = '1. 0'?>).XmldeclarationThe node must be the first node in the document. It cannot have sublevels. It isDocumentThe child level of the node. It can have attributes that provide version and encoding information.
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.