Link to home
Start Free TrialLog in
Avatar of jrspano
jrspanoFlag for United States of America

asked on

xmldocument to string

I have a variable dimed as an xmldocument in .net

I want to take the xml in the doc and put it in a string variable. Anyone know how to do this

Avatar of soferstam
soferstam

I believe it is .xml property of the DOMDocument.
I don't know net,but the objects are the same.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
var currNode;
xmlDoc.async = false;
xmlDoc.load("books.xml");
currNode = xmlDoc.documentElement.childNodes.item(0);
alert(currNode.xml);

You also can use xmlDoc.xml

ASKER CERTIFIED SOLUTION
Avatar of anthony_glenwright
anthony_glenwright
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Objects are not the same in .NET

You will have to use different classes in .NET

this is what it looks like in c-charp:

//c-sharp
//declare instance of xml doc
XmlDocument doc = new XmlDocument();
//load xml into memory
doc.Load("c:\\contacts.xml");
//get hold of the root node
doc.GetElementsByTagName("contact");
//convert xml into string variable using the innerxml method
string a = doc.InnerXml.ToString();
//display in console window
Console.WriteLine(a);

'vb
Dim doc As System.Xml.XmlDocument
doc = New System.Xml.XmlDocument()

doc.Load("c:\contacts.xml")
doc.GetElementsByTagName("contact")

Dim strXML As String
strXML = doc.InnerXml.ToString()
Console.WriteLine(strXML)

Have fun...
Avatar of jrspano

ASKER

worked great thanks