简体   繁体   中英

appending xml string to dom.documentElement

I have an xml string like the following:

var xml = "<tests><test>90<test></tests>"

I'd like to create elements from var xml and append this to dom.documentElement.

I've tried dom.documentElement(xml), but that throws an error.

uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMElement.appendChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" 

How would I do this?


Here's some context.

I'm using the dom to manipulate xml elements. The end output is to use XMLSerializer's serializeToString method and generate the final xml I'll be using to do REST calls.

I ended up using the DOMParser().

var p = new DOMParser();
dom.documentElement.appendChild(p.parseFromString(xml, "text/xml").documentElement);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM