Download presentation
Presentation is loading. Please wait.
Published byEzra Boyd Modified over 9 years ago
1
WORKING WITH XML IN THE.NET FRAMEWORK
2
Accessing an XML File Basic activities: open it, read it.NET Framework provides structured and unstructured mechanisms for processing XML files i.e.: stream of data, or hierarchical structure Basic activities: open it, read it.NET Framework provides structured and unstructured mechanisms for processing XML files i.e.: stream of data, or hierarchical structure
3
XML Classes We Will Use XmlReader - process as you go XmlNode – represents nodes in an XML file XmlDocument – represents entire XML document XmlDataDocument – data enabled XmlReader - process as you go XmlNode – represents nodes in an XML file XmlDocument – represents entire XML document XmlDataDocument – data enabled
4
Delaney, Kalen Inside Microsoft SQL Server Microsoft Press Burton, Kevin.NET Common Language Runtime Sams Cooper, James W. C# Design Patterns Addison Wesley Hull, Dale E. The Joys of SOA and Web Services With.NET Fulfilled Life Press Guy, Class E. Dressing For Success As A.NET Developer Gentleman's Quarterly Delaney, Kalen Inside Microsoft SQL Server Microsoft Press Burton, Kevin.NET Common Language Runtime Sams Cooper, James W. C# Design Patterns Addison Wesley Hull, Dale E. The Joys of SOA and Web Services With.NET Fulfilled Life Press Guy, Class E. Dressing For Success As A.NET Developer Gentleman's Quarterly
5
Document Object Model (DOM) Internet standard for representing the information contained in an HTML or XML file as a tree of nodes.NET Framework supports Level 1 core specs and Level 2 core specs It extends the specifications by adding objects, methods and properties not defined in the spec Internet standard for representing the information contained in an HTML or XML file as a tree of nodes.NET Framework supports Level 1 core specs and Level 2 core specs It extends the specifications by adding objects, methods and properties not defined in the spec
6
XML Document Structure Series of nested items, including elements and attributes Any nested structure can be transformed into an equivalent tree structure if the outermost nested item is made the root of the tree The next nested items are children of the root, etc. Series of nested items, including elements and attributes Any nested structure can be transformed into an equivalent tree structure if the outermost nested item is made the root of the tree The next nested items are children of the root, etc.
7
The XmlReader Class Forward-only, read-only access to an XML file Similar to a cursor in processing a relational database Move through the file with Read() Read() returns the next node Forward-only, read-only access to an XML file Similar to a cursor in processing a relational database Move through the file with Read() Read() returns the next node
8
Important Properties of XmlReader Depth EOF HasAttributes IsEmptyElement Name NodeType Value Depth EOF HasAttributes IsEmptyElement Name NodeType Value
9
Important Methods of XmlReader GetAttribute() IsStartElement() MoveToElement() MoveToFirstElement() MoveToNextAttribute() Read() Skip() GetAttribute() IsStartElement() MoveToElement() MoveToFirstElement() MoveToNextAttribute() Read() Skip()
10
XmlTextReader XmlReader is an abstract class You will use XmlTextReader, which inherits from XmlReader, and implements its methods Used with text streams XmlReader is an abstract class You will use XmlTextReader, which inherits from XmlReader, and implements its methods Used with text streams
11
Demonstration Projects XmlTextReader – uses XmlTextReader to retrieve all entries AttributesElements – using XmlTextReader to retrieve selected entities XmlDocument - uses XmlDocument and XmlNode classes to retrieve node objects from a Document object XmlTextReader – uses XmlTextReader to retrieve all entries AttributesElements – using XmlTextReader to retrieve selected entities XmlDocument - uses XmlDocument and XmlNode classes to retrieve node objects from a Document object
12
Demonstration Projects (cont’d) DataSetFromXml – synchronizes by retrieving a DataSet object from an XmlDataDocument object XmlFromDataSet – creates an XmlDataDocument from a DataSet object SynchronizeWithXmlSchema – uses an XML schema to create a DataSet object DataSetFromXml – synchronizes by retrieving a DataSet object from an XmlDataDocument object XmlFromDataSet – creates an XmlDataDocument from a DataSet object SynchronizeWithXmlSchema – uses an XML schema to create a DataSet object
13
The XmlNode Class Individual items in a tree representation of an XML file are called “nodes” The DOM assigns node types to different kinds of nodes In the.NET Framework, the possible node types are listed in the XmlNodeType enumeration Individual items in a tree representation of an XML file are called “nodes” The DOM assigns node types to different kinds of nodes In the.NET Framework, the possible node types are listed in the XmlNodeType enumeration
14
Members of The XmlNodeType Enumeration Attribute Comment Document DocumentFragment Element EndElement EndEntity Attribute Comment Document DocumentFragment Element EndElement EndEntity
15
Members of The XmlNodeType Enumeration (cont’d) Entity EntityReference None Notation ProcessingInstruction SignificantWhitespace Text Whitespace XmlDeclaration Entity EntityReference None Notation ProcessingInstruction SignificantWhitespace Text Whitespace XmlDeclaration
16
The XmlNodeClass Has a rich set of properties and methods You can retrieve or set information about an entity represented by an XmlNode object You can use its methods to navigate the DOM Has a rich set of properties and methods You can retrieve or set information about an entity represented by an XmlNode object You can use its methods to navigate the DOM
17
Important Properties of The XmlNode Class Attributes ChildNodes FirstChild HasChildNodes InnerText InnerXml LastChild Attributes ChildNodes FirstChild HasChildNodes InnerText InnerXml LastChild
18
Important Properties of The XmlNode Class (cont’d) Name NextSibling NodeType OuterXml OwnerDocument ParentNode PreviousSibling Name NextSibling NodeType OuterXml OwnerDocument ParentNode PreviousSibling
19
Important Methods of The XmlNode Class AppendChild() CloneNode() InsertAfter() InsertBefore() PrependChild() RemoveAll() AppendChild() CloneNode() InsertAfter() InsertBefore() PrependChild() RemoveAll()
20
Important Methods of The XmlNode Class (cont’d) RemoveChild() ReplaceChild() SelectNodes() SelectSingleNode() WriteContentTo() WriteTo() RemoveChild() ReplaceChild() SelectNodes() SelectSingleNode() WriteContentTo() WriteTo()
21
Synchronizing DataSet Objects With XML The DataSet object is an ADO.NET object that represents the structure and data of a relational database The System.Xml namespace automatically synchronizes a DataSet object with an XML file The DataSet object is an ADO.NET object that represents the structure and data of a relational database The System.Xml namespace automatically synchronizes a DataSet object with an XML file
22
The XmlDocument Class Represents an entire XML document XmlNode objects are associated with an XmlDocument object You navigate through the DOM representation of an XML document with these two classes Represents an entire XML document XmlNode objects are associated with an XmlDocument object You navigate through the DOM representation of an XML document with these two classes
23
Additional Members of The XmlDataDocument Class DataSet GetElementFromRow() GetRowFromElement() Load() DataSet GetElementFromRow() GetRowFromElement() Load()
24
Synchronization Process You can start with –An XmlDataDocument object –A full DataSet object –A schema-only DataSet object You can start with –An XmlDataDocument object –A full DataSet object –A schema-only DataSet object
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.