
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Handling Invalid Characters in an XML String
|
849
The DetectXmlChanges method results in the following output:
Element: <Node5> inserting with null value
Element: <Node5> inserted with null value
Element: <#text> inserting with value Fifth Element
Element: <#text> inserted with value Fifth Element
Element: <#text> changing with value First Node
Element: <#text> changed with value 1st Node
Element: <Node4> removing with null value
Element: <Node4> removed with null value
<?xml version="1.0"?><!-- My sample XML --><?pi myProcessingInstruction?><Root><
Node1 nodeId="1">1st Node</Node1><Node2 nodeId="2">Second Node</Node2><Node3 nod
eId="3">Third Node</Node3><Node5>Fifth Element</Node5></Root>
Discussion
With an XmlDocument, you can traverse both forward and backward in the XML
stream, as well as use
XPath navigation to find nodes. If you are just reading XML
and not modifying it, and you have no need for traversing backward through the
nodes, you should avoid using
XmlDocument, since XmlReader is faster for reading and
XmlWriter is faster for writing (both have less overhead than XmlDocument). The .NET
Framework team did a nice job of giving XML processing flexibility, but if you use a
class with more functionality than you need, you will pay the resulting performance
penalty.
See Also
See the