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!

convert xmlnode to a xmldocument

Status
Not open for further replies.

cyrus71

Programmer
Feb 6, 2006
34
SE
Hi,
I am trying to get a xml file(document) from a web serveice and save.

here is my code:
string file = "C:\\temp\\MyFeed.xml";
WSRef.WS RSSFWS = new WSRef.WS();
string WSPath = "C:\\temp\\WSFeed.xml";
XmlNode result = WS.GetRSSFeed(file);
XmlDocument doc = new XmlDocument();
doc.AppendChild(result);
//doc.ImportNode(result, false);
doc.Save(WSPath);
following Exception make me crazy.
The node to be inserted is from a different document context.

and when i use doc.ImportNode(result, false); I get this:
Invalid XML document, The document does not have a root element..

help me please.
 
try this:

string file = "C:\\temp\\MyFeed.xml";
WSRef.WS RSSFWS = new WSRef.WS();
string WSPath = "C:\\temp\\WSFeed.xml";
XmlNode result = WS.GetRSSFeed(file);
XmlDocument doc = new XmlDocument();
//doc.DocumentElement.AppendChild(result);
doc.DocumentElement.ImportNode(result, false);
doc.Save(WSPath);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top