开发者

How can I add attributes to the root node of an XML doc in javascript

开发者 https://www.devze.com 2022-12-19 11:50 出处:网络
I am using the sarissa javascript library to create xml on the client in a web application. My question is how can I add attributes to the root node? I am really trying to pass a small xml string to t

I am using the sarissa javascript library to create xml on the client in a web application. My question is how can I add attributes to the root node? I am really trying to pass a small xml string to the server like basically a 1 liner of XML. I tried this and it doesn't w开发者_如何转开发ork. oDomDoc does not support the "setAttributeNode" method. I must be adding the attribute incorrectly.

var oDomDoc = Sarissa.getDomDocument("", "item");
var attrib = document.createAttribute("something");
attrib.nodeValue = "something";
oDomDoc.setAttributeNode(attrib);

I feel I must be trying to add it to the document object instead of the node. Can anyone point me in the right direction. Thanks so much for any help.

Cheers, ~ck in San Diego


Yes, you are creating an attribute on the "document" element which is not what you want to do.

Try to use the document node to create a new element, then use the setAttribute() method on the newly created element.

Check out JavaScript DOM, does not require any special library, just standard JavaScript DOM methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消