13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Table 2-3: Public Methods of the XmlReader ClassMethodReadElementStr<strong>in</strong>gReadEndElementReadInnerXmlReadOuterXmlReadStartElementReadStr<strong>in</strong>gResolveEntitySkipDescriptionon page 41.)Reads and returns the text from a text-only element.Checks that the current content node is an end tagand advances the reader to the next node. Throwsan exception if the node is not an end tag.Reads and returns all the content below the currentnode, <strong>in</strong>clud<strong>in</strong>g markup <strong>in</strong><strong>for</strong>mation.Reads and returns all the content <strong>in</strong> and below thecurrent node, <strong>in</strong>clud<strong>in</strong>g markup <strong>in</strong><strong>for</strong>mation.Checks that the current node is an element andadvances the reader to the next node. Throws anexception if the node is not a start tag.Reads the contents of an element or a text node asa str<strong>in</strong>g. This method concatenates all the text upuntil the next markup. For attribute nodes, call<strong>in</strong>gthis method is equivalent to read<strong>in</strong>g the attributevalue.Expands and resolves the current EntityReferencenode.Skips the children of the current node.In addition to the methods listed <strong>in</strong> Table 2-3, the XmlReader class also features acouple of static (shared, if you speak only <strong>Microsoft</strong> Visual Basic) methods namedIsName and IsNameToken. Both take a str<strong>in</strong>g and return a Boolean value. The returnvalue <strong>in</strong>dicates whether the given str<strong>in</strong>g complies with the respective def<strong>in</strong>itions of aName and a Nmtoken (name token) accord<strong>in</strong>g to the W3C <strong>XML</strong> 1.0 Recommendation.In <strong>XML</strong> 1.0, a Name is a str<strong>in</strong>g that beg<strong>in</strong>s with a letter, an underscore (_), or a colon (:)and cont<strong>in</strong>ues with letters, digits, hyphens, underscores, and colons. A Nmtoken, on theother hand, is any non-zero-length mixture of name characters—that is, letters, digits,hyphens, underscores, and colons.NoteA static member (as opposed to an <strong>in</strong>stance member) of a class is ak<strong>in</strong>d of global member that belongs to the type itself rather than to aspecific <strong>in</strong>stance of the class. Whereas an <strong>in</strong>stance of a class conta<strong>in</strong>s aseparate copy of all <strong>in</strong>stance members, there is only one copy of eachstatic member. Static members can't be referenced through an <strong>in</strong>stance.Instead, you must reference them through the type name:Console.WriteL<strong>in</strong>e(XmlReader.IsName("D<strong>in</strong>oEsposito"));Members that <strong>in</strong> C# are called static and declared with the statickeyword, <strong>in</strong> Visual Basic .<strong>NET</strong> are called shared and are declared withthe Shared keyword. Aside from this, their usage is identical.Recognized Node TypesEach node <strong>in</strong> an <strong>XML</strong> source is of a certa<strong>in</strong> type. The NodeType property is a read-onlyproperty that returns the type of the current node. The returned value belongs to theXmlNodeType enumeration, which comprises the node types listed <strong>in</strong> the Table 2-4.25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!