-
innerHTML Alternative in Firefox
I am receiving an HTML fragment from the server as a response from an XmlHTTP request. I would like, if possible, to avoid using the innerHTML property to append the fragment to the document. I have therefore loaded the reponse into an XML Dom object (created with createDocument) and appended this to the HTML DOM.
The problem, while it appends the information to the element, only the text is appended and none of the HTML is parsed, resulting in just a concatonated string. For some reason, the browser ignores any of the markup.
This seems to be the case in both the DOM compliant browsers I have tested the code in (Firefox and Netscape). So I am thinking that this is a feature of the DOM API rather than a bug. If indeed this, is the case, how do I get the DOM to recognise the XML I am appending as XHTML.
Below is the Javascript I am using to append the HTML fragment.
Code:
var transformed = '';
var oXml = loadXmlFromString(xmlHTTP.responseText);
if (window.ActiveXObject) { // Internet Explorer
bookSummary.innerHTML = oXml.xml;
} else if (oXml.documentElement){ // w3c compliant browsers
if (bookSummary.firstChild) {
bookSummary.replaceChild(oXml.documentElement,bookSummary.firstChild);
} else {
bookSummary.appendChild(oXml.documentElement);
}
}
function loadXmlFromString(sXml)
{
var oXml = getXML();
if (window.ActiveXObject) { // Internet Explorer
oXml.loadXML(sXml);
return oXml;
} else if ((typeof DOMParser) != "undefined") { // w3c Compliant Browsers
var parser = new DOMParser();
var ret = parser.parseFromString(sXml, 'text/xml');
return ret;
}
throw 'Cannot load XMl from string';
}
function getXML()
{
return document.implementation.createDocument('', '', null);
}
Similar Threads
-
Replies: 2
Last Post: 04-17-2007, 02:04 PM
-
Replies: 3
Last Post: 05-21-2005, 07:30 PM
-
By Brent... in forum .NET
Replies: 12
Last Post: 06-13-2002, 08:12 PM
-
Replies: 1
Last Post: 04-12-2002, 08:35 AM
-
By Brenda in forum Open Source
Replies: 0
Last Post: 12-03-2001, 02:59 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|