
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Reading XML on the Web
|
835
See Also
See the “XmlReader Class,” “XmlNodeType Enumeration,” and “MemoryStream
Class” topics in the MSDN documentation.
15.2 Reading XML on the Web
Problem
Given a URL that points to an XML document, you need to grab the XML.
Solution
Use the XmlReader constructor that takes a URL as a parameter:
string url = "http://localhost/xml/sample.xml";
using (XmlReader reader = XmlReader.Create(url))
{
Comment A comment in the XML:
<!—my comment -->.
Document The root of the XML document tree.
DocumentFragment Document fragment node.
DocumentType The document type declaration.
Element An element tag:
<myelement>.
EndElement An end element tag:
</myelement>.
EndEntity Returned at the end of an entity after calling ResolveEntity.
Entity Entity declaration.
EntityReference A reference to an entity.
None This is the node returned if Read has not yet been called on the XmlReader.
Notation A notation in the DTD (document type definition).
ProcessingInstruction The processing instruction:
<?pi myProcessingInstruction?>.
SignificantWhitespace Whitespace when mixed content model is used or when whitespace is being preserved.
Text Text content for a node.
Whitespace The whitespace between markup entries.
XmlDeclaration The first node in the document that cannot have children:
<?xml version='1.0'?> ...