Saturday, June 5, 2010

Reading an Xml

1. Parsing the XML 1.0 byte stream

a. XmlTextReader : Parses the XML 1.0 Byte Stream and the complexities of the XML 1.0 syntax by serving up the document as a logical-tree structure through higher-level APIs.

- Performance
- Memory
- Traversal
- Operation
- XPath
- XSLT
- Fastest
- Most efficient as only one node needs to be in memory
- Forward Only
- Read Only
- No
- No

2. Processing the Logical Tree via XML APIs

i. Streaming

a. XmlReader

- Models read an Xml as a forward-only, linear stream of nodes.
- XmlReader allows the client to pull the nodes one at a time much like the firehose cursor model in data access technology.


ii. Traversal Oriented

a. XmlNode (XmlDocument)

- Built on top of XmlReader


- Performance
- Memory
- Traversal
- Operation
- XPath
- XSLT
- 2 to 3x slower than XmlTextReader
- Loads entire Xml/Tree Structure in Memory
- Full Traversal
- Read/Write
- Yes
- No

b. XPathNavigator

- Uses a cursor model, which gives the underlying implementation more options in terms of how the tree is actually stored.

- Performance
- Memory
- Traversal
- Operation
- XPath
- XSLT
- Faster than XmlDocument
- More efficient than XmlDocument
- Full Traversal
- Read Only
- Yes
- Yes

3. Choosing which class


  • What kind of reader should I use?
    Use XmlTextReader if:
    * Performance is your highest priority and…
    * You don't need XSD/DTD validation and…
    * You don't need XSD type information at runtime and…
    * You don't need XPath/XSLT services

    Use XmlValidatingReader if:

    * You need XSD/DTD validation or…
    * You need XSD type information at runtime or…
  • Should I load the tree into memory?

    Use the DOM if:

    * Productivity is your highest priority or…
    * You need XPath services or…
    * You need to update the document (read/write)
  • XmlDocument or XPathDocument?
    * You need to execute an XSLT transformation or…
    * You want to leverage an implementation (like XPathDocument)

No comments: