Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XmlElement to string...how to?

Status
Not open for further replies.

astromenix

Technical User
Dec 4, 2002
9
GR
Hello,
I ve got a web service that accepts XmlElement as an input parameter.
Then within my web method i would like to convert it to sting and then pass the string to my the stored procedure and use OPENXML to insert the values to SQL Server.
[WebMethod]
public string StoreBooking([XmlAnyElement]XmlElement booking)
{
XmlDocument doc = new XmlDocument();
StringWriter sw = new StringWriter();
try
{
doc.AppendChild(booking);
XmlTextWriter xw = new XmlTextWriter(sw);
doc.WriteTo(xw);
}

catch (XmlException e)
{
return e.ToString();
}
return doc.ToString();

But for some reason i cant add the XmlElement to the XmlDocument.
Please help me
Thanks in advanse.
 
Code:
  XmlDocument doc = new XmlDocument();
       StringWriter sw = new StringWriter();
       try
       {
    doc.AppendChild(booking);
It's because your booking variable belongs to a different XmlDocument than your doc variable. (All elements in a XML document have to belong to the same XmlDocument). Use the OwnerDocument property of your booking node to retrieve the XmlDocument object it belongs to, then use that variable to create your new element.

Chip H.



If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top