Equivalent of documentElement.innerHTML for XML
I have some javascript that runs in Firefox and accesses the contents of a second tab. I do not have control of the content开发者_运维百科s of the second tab.
When the second tab is HTML. I am able to read the contents of the tab as a string and also clear the tab contents using
document.documentElement.innerHTML
But I cannot figure out how to do this when there is an XML document loaded in the second tab (i.e. no enclosing html tag so innerHTML doesnt work). The two things I need to do are: (1) read tab contents, (2) clear tab contents.
Use XMLSerializer to convert a node tree to a string and DOMParser to convert a string to a node tree. As far as I know, they only work in Firefox, but as of Firefox 4, I believe they work in HTML documents as well as XML documents. Note that to clear nodes you can just use removeChild.
You should be able to use element.nodeValue
Edit: As pointed out in the comments this is not possible due to limitations detailed here: https://developer.mozilla.org/en/nodeValue
精彩评论