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.
精彩评论