all groups > dotnet xml > august 2005 >
You're in the

dotnet xml

group:

xmldocument vs. xpathdocument



xmldocument vs. xpathdocument Ben R.
8/31/2005 11:14:03 AM
dotnet xml: Hi,

Could someone explain the functional difference between these classes? From
what I understand, xpathdocument is faster in some scenarios, but I'm not
sure why. Further, why is it that the method of getting xml data into these
two classes differs? (xmldocument uses the load method, whereas xpathdocument
doesn't have this available and one must specify the path to the xml data in
the constructor, or so it seems). Any help would be appreciated. Thanks...

Re: xmldocument vs. xpathdocument Ben R.
8/31/2005 11:47:10 AM
Thanks for the quick response, Martin. Any idea about why there's 2 different
ways to get the xml data into the two classes?

-Ben

[quoted text, click to view]
Re: xmldocument vs. xpathdocument Martin Honnen
8/31/2005 8:36:31 PM


[quoted text, click to view]


[quoted text, click to view]

XmlDocument implements a document object model which allows reading out
data from the document and changing the document (changing the value of
an attribute, changing the contents of a text node, inserting nodes,
removing nodes).
XPathDocument allows a read only access to an XML document.


--

Martin Honnen --- MVP XML
Re: xmldocument vs. xpathdocument Martin Honnen
8/31/2005 9:04:59 PM


[quoted text, click to view]

One reason could be an attempt to keep the methods that MSXML implements
for DOM documents, there a DOM document has a load method and a loadXML
method and the DOM XmlDocument in .NET has those two methods too. But
that is just a guess, only the API designers can tell why they did that.


--

Martin Honnen --- MVP XML
Re: xmldocument vs. xpathdocument Pascal Schmitt
9/1/2005 12:00:00 AM
[quoted text, click to view]

A reason could be that, if you're using XPathDocument, you allways have
to load XML, as read-only would have no sense if you did not load
anything. But the XmlDocument allows you to create XML from scratch,
without having to load anything. You also can reuse it, load something,
modify it, save it somewhere, modify it, safe it again, load something
else...

But it would be nice to have a Constructor of XmlDocument wich acts like
those of XPathDocument, it's one line of code less... :)

Re: xmldocument vs. xpathdocument Oleg Tkachenko [MVP]
9/1/2005 10:40:38 AM
[quoted text, click to view]

XmlDocument and XPathDocument are based on different data models.
XmlDocument is based on W3C XML DOM, which is object model that
basically covers all XML syntax, including low level syntax sugar such
as entities, CDATA sections, DTD, notations etc. That's document-centric
model and it allows for full fidelity when loading/saving XML documents.

XPathDocument is based on XPath 1.0 data model which is read-only XML
Infoset-compatible data-centric object model that covers only
semantically significant parts of XML, leaving out insignificant syntax
details - no DTD, no entities, no CDATA, no adjacent text nodes, only
significant data expressed as a tree with seven types of nodes. Simple
and lightweight.
That's why XPathDocument is preffered data store for read-only
scenarios, especially with XPath or XSLT involved.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
AddThis Social Bookmark Button