C Sharp wrote:
I think I have to create an XMLDocument first
and then add XMLElements to it.
1. Is this the right approach?
2. If so, how do I send just one element out of many over the wire?
Should I duplicate that element in a new XmlDocument (the new
XmlDocument having just one element?)?
First of all, if you want to create XML to send it for instance over
HTTP then there is no need to use XmlDocument, it suffices to create the
XML on the fly with an XmlWriter, for instance created over the request
stream of an HttpWebRequest.
If you want to use XmlDocument, the DOM implementation in the .NET
framework, then yes, you always need an XmlDocument instance to use its
factory methods like CreateElement to create other node types (like
element nodes). There is no absolute need however to insert a created
element node into an XmlDocument, if you want to you can serialize a
single (non-document) node like an XmlElement, using the OuterXml
property for instance or of course using the WriteTo method
<http://msdn2.microsoft.com/en-us/library/system.xml.xmlelement.writeto.aspx>
again for instance to an XmlWriter created over the request stream of an
HttpWebRequest.
On the receiving end, if you also want to use the DOM there, you need to
create an XmlDocument and then you have various choices to convert the
stream of markup you receive into nodes, you can use the Load method of
the XmlDocument, you can use the ReadNode method
<http://msdn2.microsoft.com/en-us/library/system.xml.xmldocument.readnode.aspx>
to pass in an XmlReader and create a node. Or you can create an
XmlDocumentFragment and set its InnerXml.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/