...

View Full Version : retrieving HTML from responseXML



fruminovator
09-14-2008, 02:37 PM
I get back an xml doc which contains HTML info that I want to retrieve with all of its tags. But my "content" gets a null value. If content doesn't contain html tags then it works fine.

Here is the code:
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
var xmlDoc=xmlHttp.responseXML.documentElement;
document.getElementById("title").value=
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
document.getElementById("subtitle").value=
xmlDoc.getElementsByTagName("subtitle")[0].childNodes[0].nodeValue;

// update content editor
var editor = FCKeditorAPI.GetInstance('myFCKeditor');
var content = xmlDoc.getElementsByTagName("content")[0].childNodes[0].nodeValue;
editor.SetHTML(content);
}

Here is the xml:
<page>
<title>About the Mishna program</title>
<subtitle>Mishna program</subtitle>

<content>
<p>
The Mishna Program is a must for anyone serious in developing a strong bekius in mishnaios which is critical to learning gemara.
</p>
</content>
</page>

Thanks for any help.

shyam
09-14-2008, 03:33 PM
since you are extracting the contents of the xml document the the nodeValue of any element node (in your case content) is always null. what you should be doing is serializing the contents of the content tag to a string


function xmlContent(xmlNode) {
if ( window.XMLSerializer ) {
// FF
return new XMLSerializer().serializeToString(xmlNode);
}
// IE
return xmlNode.xml;
}
...

var content = xmlDoc.getElementsByTagName("content")[0];
editor.SetHTML(xmlContent(content ));

fruminovator
09-14-2008, 03:42 PM
thanks. I'll try that.

fruminovator
09-14-2008, 03:52 PM
It crashes on this line (using FF):

return new XMLSerializer().serializerToString(xmlNode);

What am I missing?

fruminovator
09-14-2008, 04:05 PM
Also
It crashes on this line (using FF):

return (new XMLSerializer()).serializerToString(xmlNode);

What am I missing?

shyam
09-14-2008, 04:14 PM
Also
It crashes on this line (using FF):

return (new XMLSerializer()).serializerToString(xmlNode);

What am I missing?

sorry my bad :(...typo


return (new XMLSerializer()).serializeToString(xmlNode);

fruminovator
09-14-2008, 05:09 PM
yeah, I figured that out.
thanks.

It works now!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum