Ramya A wrote:
I have to create an XML in the following syntax:
<RESPONSE>
<QueueItems>
<Node1>.....
<Node2>.....
</QueueItems>
<QueueItems>
...
</QueueItems>
</RESPONSE>
Iam building this through a SqlDataReader object. My problem is I
cannot get DOM object to create the QueueItems node. Please help!
If you do
sqlCommand.ExecuteXmlReader
instead of
sqlCommand.ExecuteReader
then you have an XmlReader returned which you can directly feed to the
Load method of an XmlDocument. You will need to use a Transact-SQL
statement with a valid FOR XML clause.
If that does not help then you need to use the DOM the proper way e.g.
XmlDocument xmlDocument = new XmlDocument();
XmlElement response = xmlDocument.CreateElement("RESPONSE");
XmlElement items = xmlDocument.CreateElement("QueueItems");
XmlElement node = xmlDocument.CreateElement("Node1");
items.AppendChild(node);
response.AppendChild(items);
xmlDocument.AppendChild(response);
So the proper way is to use CreateElement on the document itself to
create the element node and then use AppendChild on the node you want
the element to be a child of.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/