.NET Samples - How To: XML Data
This section includes the following samples:
DataSetMapXMLData Sample
SaveDataSetMapXSDSchema Sample
LoadDataSetXMLData Sample
DataSetMapXSDSchema Sample
ReadXmlFile Sample
ReadXmlStream Sample
XmlReadFromUrl Sample
MultipleXmlReader Sample
DOMInterfaceXmlDocument Sample
SaveXmlDocument Sample
LoadXmlDocument Sample
WriteXmlFile Sample
XmlDocumentEvent Sample
SchemaCollection Sample
XmlReadWriteSchema Sample
ValidationReadingXML Sample
QueryXmlDocumentXPath Sample
NavigateXmlDocument Sample
XmlNameSpace Sample
XPathExpression Sample
SaveDataSetXMLData Sample
XmlSchemaObjectModel Sample
XmlNodeReader Sample
TransformXML Sample
StreamXmlDocument Sample
DataSetMapXMLData Sample
This sample illustrates how to create DataSet mappings from XML data.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Data; System.Xml
Classes used in this sample:
DataSet; Console; String; Xml; Table; XmlDataDocument; Object; StringWriter; Import; Exception; DataColumn; Page; DataTable; Array; Debug; EventArgs; StreamReader; Path; Stream; DataRow
SaveDataSetMapXSDSchema Sample
This sample illustrates how to save the internal DataSet mappings to an XML Schema Definition Language (XSD) schema file.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Data; System.Xml
Classes used in this sample:
DataSet; Console; Table; DataColumn; String; Exception; DataRow; Xml; DataTable; XmlDataDocument; StringWriter; Type; Import; Stream; Object; DataRelation; StreamWriter; Page; EventArgs; Array; Debug; XmlSchema
LoadDataSetXMLData Sample
This sample illustrates how to load a DataSet with XML data.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Data; System.Xml
Classes used in this sample:
DataSet; Console; Table; Xml; String; XmlDataDocument; Stream; StreamReader; Exception; Object; StringWriter; Import; Path; Page; DataTable; DataRow; DataColumn; Type; Array; Debug; XmlSchema; EventArgs
DataSetMapXSDSchema Sample
This sample illustrates how to create DataSet mappings from a supplied XML Schema Definition Language (XSD) schema.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
DataSet; Xml; Table; XmlDataDocument; Console; String; StreamReader; Stream; Exception; StringWriter; Import; Type; Debug; EventArgs; Page; Path; XmlSchema; Object
ReadXmlFile Sample
This sample illustrates how to read XML from a file using the XmlTextReader class.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
Xml; Console; File; Type; Form; String; XmlNode; Attribute; Process; XmlTextReader; XmlText; TextReader; XmlDeclaration; Exception; XmlReader; Import; StringWriter; Object; EventArgs; Debug; Path; Page
ReadXmlStream Sample
This sample illustrates how to read XML from a stream using the XmlTextReader class.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
Xml; Console; Stream; Type; Form; String; XmlNode; Attribute; Process; XmlTextReader; XmlText; TextReader; StringReader; XmlReader; Exception; StringWriter; Import; Object; EventArgs; Debug; Page
XmlReadFromUrl Sample
This sample illustrates how to read XML from a URL using the XmlTextReader class.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
Xml; Console; Type; Form; XmlNode; XmlText; TextReader; XmlTextReader; Attribute; String; Process; XmlDeclaration; Url; Import; Exception; StringWriter; EventArgs; Page; Object; Debug
MultipleXmlReader Sample
This sample illustrates how to create and use an XmlNodeReader to provide fast, noncached, forward-only access to XML data in an XML node.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
Xml; Console; XmlReader; Type; String; XmlNode; XmlTextReader; TextReader; XmlText; File; XmlNamespaceManager; Context; Import; Stream; XmlParserContext; Exception; NameTable; Table; FileStream; StringWriter; Object; Page; Debug; EventArgs; Path
DOMInterfaceXmlDocument Sample
This sample illustrates the classes which implement the Document Object Model (Core) of the W3C Document Object Model (DOM) Specification.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
Xml; XmlDocument; Console; String; XmlNode; Form; XmlText; TextReader; XmlTextReader; Import; Process; Type; Exception; StringWriter; Object; EventArgs; Debug; Page; XmlNamedNodeMap; File; Path; Attribute
SaveXmlDocument Sample
This sample illustrates how to update and save XML using the XmlDocument class, which is an implementation of the W3C Document Object Model (DOM).
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
Xml; XmlDocument; String; Console; Exception; Import; StringWriter; Path; Debug; Page; Object; TextReader; XmlTextReader; XmlText; XmlNode; EventArgs
LoadXmlDocument Sample
This sample illustrates how to load XML into the XmlDataDocument class.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
Xml; XmlDocument; String; Console; XmlDataDocument; StringWriter; Exception; Import; Debug; Object; Path; Page; EventArgs
WriteXmlFile Sample
This sample illustrates how to write XML to a file using the XmlTextWriter class.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml
Classes used in this sample:
Xml; XmlText; TextWriter; XmlTextWriter; Console; String; File; Form; Type; Attribute; TextReader; XmlTextReader; XmlNode; Process; StringWriter; Import; Exception; EventArgs; Page; XmlReader; Object; Path; Debug
XmlDocumentEvent Sample
This sample illustrates how to receive and handle events when nodes in an XML document change.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml; System.Globalization; System.Xml.XPath
Classes used in this sample:
Xml; XmlDocument; Console; XmlNode; String; Object; XmlElement; EventArgs; XmlNodeList; Exception; Import; Path; EventHandler; XmlNodeChangedEventArgs; StringWriter; XmlNodeChangedEventHandler; Page; Debug; XmlDocumentFragment
SchemaCollection Sample
This sample illustrates how to use the XmlSchemaCollection class used by the XmlValidatingReader for efficient data validation.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml; System.Xml.Schema
Classes used in this sample:
Xml; Console; String; Type; Exception; XmlValidatingReader; EventHandler; XmlSchema; Path; XmlText; XmlSchemaCollection; StringWriter; EventArgs; Import; TextReader; XmlTextReader; ValidationEventHandler; Page; Object; ValidationEventArgs; Message; XmlNode; Uri; Debug; Attribute
XmlReadWriteSchema Sample
This sample illustrates how to read an XML Schema Definition Language (XSD) file into the Schema Object Model (SOM).
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml; System.Xml.Schema
Classes used in this sample:
Xml; String; StringWriter; Console; XmlWriter; XmlText; Form; TextWriter; XmlTextWriter; Exception; XmlSchema; Import; XmlTextReader; TextReader; Debug; EventArgs; Object; Path; Page
ValidationReadingXML Sample
This sample illustrates how to apply validation when reading and parsing XML data using the XmlValidatingReader class.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml; System.Xml.Schema
Classes used in this sample:
Xml; XmlValidatingReader; Console; XmlTextReader; TextReader; XmlText; String; Exception; Type; XmlSchemaCollection; XmlSchema; Path; ValidationEventHandler; XmlException; StringWriter; EventHandler; EventArgs; Import; ValidationEventArgs; Uri; Message; Object; Page; Debug
QueryXmlDocumentXPath Sample
This sample illustrates how to query an XPathDocument with a W3C XML Path Language (XPath) expression supplied to the XPathNavigator class.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml; System.Xml.XPath
Classes used in this sample:
Path; Xml; XmlDocument; String; XPathNavigator; Console; XPathNodeIterator; XPathDocument; StringWriter; Import; Exception; EventArgs; Page; Object; Debug
NavigateXmlDocument Sample
This sample illustrates how to navigate XML documents with an XPathNavigator created from an XPathDocument.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml; System.Xml.XPath
Classes used in this sample:
Path; XPathNavigator; Console; Xml; XmlDocument; String; XPathNodeIterator; XPathDocument; Type; Form; Attribute; StringWriter; Import; Exception; Page; Object; Debug; EventArgs
XmlNameSpace Sample
This sample shows how to select namespace-specific XML data from an XmlDocument.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml; System.Xml.XPath
Classes used in this sample:
Xml; String; XmlNode; XmlDocument; Console; Form; XmlNamespaceManager; Type; Exception; Import; StringWriter; Path; Page; NameTable; XmlNamedNodeMap; Object; XmlNodeList; Table; Debug; EventArgs; Attribute
XPathExpression Sample
This sample illustrates how to use an XPathExpression class to compile an XML Path Language (XPath) expression to select a node-set from an XML file.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.IO; System.Xml; System.Xml.XPath; System.Collections
Classes used in this sample:
Path; Console; XPathExpression; XPathNavigator; String; Form; Xml; XPathNodeIterator; Type; XPathDocument; Object; Comparer; Import; Process; Exception; Attribute; StringWriter; Page; EventArgs; Debug
SaveDataSetXMLData Sample
This sample illustrates how to use XmlDataDocument to save relational data from a DataSet to an XML file.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.Xml; System.IO; System.Data; System.Xml.Xsl; System.Xml.XPath
Classes used in this sample:
DataSet; Xml; Console; Table; String; DataColumn; XmlNode; Type; Form; DataRow; Exception; XmlNodeReader; DataTable; XmlDataDocument; File; Process; XmlReader; Object; DataRelation; StringWriter; Import; Attribute; Page; Debug; XmlSchema; EventArgs; Array; Path
XmlSchemaObjectModel Sample
This sample illustrates how to read two XML Schema Definition Language (XSD) schemas into an XmlSchemaCollection, navigate through the schemas that they represent, and create a fictitious XML output that is representative of the schema's output.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.Xml; System.IO; System.Xml.Schema
Classes used in this sample:
Xml; XmlSchema; Type; XmlText; TextWriter; XmlTextWriter; Attribute; String; Console; XmlSchemaAttribute; Group; Object; XmlSchemaObject; XmlSchemaSimpleType; XmlSchemaElement; XmlSchemaComplexType; XmlSchemaAttributeGroup; XmlSchemaCollection; XmlSchemaParticle; XmlSchemaNotation; XmlSchemaAnnotation; XmlSchemaGroup; Table; NameTable; XmlNameTable; XmlSchemaSequence; Path; Import; Uri; Random; StringWriter; Form; Exception; XmlSchemaDatatype; EventArgs; XmlQualifiedName; XmlSchemaAttributeGroupRef; XmlSchemaObjectCollection; XmlSchemaSimpleTypeList; Debug; XmlSchemaSimpleTypeRestriction; XmlSchemaInclude; ValueType; Page
XmlNodeReader Sample
This sample illustrates how to create and use an XmlNodeReader to provide fast, noncached, forward-only access to XML data in an XML node.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.Xml; System.IO; System.Xml.XPath
Classes used in this sample:
Xml; XmlNode; XmlNodeReader; Console; Form; Type; XmlDocument; String; Exception; StringWriter; Import; Process; Attribute; Path; Object; Page; Debug; EventArgs
TransformXML Sample
This sample illustrates how to apply an Extensible Stylesheet Language Transformation (XSLT) file to an XML document using the XslTransform class.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.Xml; System.IO; System.Xml.Xsl; System.Xml.XPath
Classes used in this sample:
Xml; Console; Path; String; Form; Type; XslTransform; Style; XPathDocument; Process; XmlNode; Exception; XmlReader; Import; Stream; TextWriter; XmlTextWriter; XmlText; StreamReader; Attribute; StringWriter; EventArgs; Page; Debug; Object
StreamXmlDocument Sample
This sample illustrates how to create an XmlReader class that reads the XML data stored in the XmlDataDocument.
Link to the online sample documentation
Link to the online sample source code
Namespaces used in this sample:
System; System.Xml; System.IO; System.Xml.Xsl; System.Xml.XPath
Classes used in this sample:
Xml; XmlDocument; Stream; Form; Type; String; Console; XmlReader; XmlNode; XmlDataDocument; Path; XslTransform; Style; Attribute; XPathNavigator; StringWriter; Import; Exception; Process; Object; Debug; EventArgs; Page