Get content from xml as plain text

wxdqz

New Member
I am trying to parse an xml string in javascript. For example the following.

<person id="1">
<name>foo</name>
<firstname>bar</firstname>
</person>
<person id="2">
<name>foo</name>
<firstname>bar</firstname>
</person>


I search for a person with a specific id. So when I find it, I want to content of the tag as plain text.
For example. if I search for person with id="1", I want to get the following string "<name>foo</name><firstname>bar</firstname>". So not only the values between the tags, but also the tags.

This is the code I use



var doc;


if (window.ActiveXObject) {
doc=new ActiveXObject("Microsoft.XMLDOM");
doc.async="false";
doc.loadXML(result);
}

else {
var parser=new DOMParser();
doc=parser.parseFromString(result,"text/xml");
}

var xmlDoc=doc.documentElement;

var cells = xmlDoc.getElementsByTagName(beginTag)

for (var i = 0; i < cells.length; i++) {
id= cells.getAttribute("id");
if ( id == "1") {
cell = cells;
}
}




So how can I get the plain text from the cell variable?

Is this possible?

Thank you.
 
Back
Top