views:

37

answers:

1

Hi Everyone, 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 work. 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

+2  A: 

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 Javscript DOM, does not requrie any special library, just standard javascript DOM methods.

Harley Green
perfect. Thanks!
Hcabnettek