Suppose I have downloaded a valid XML document via Ajax (var docum = request.responseXML;). Now how do I find out the name of the root element?
A:
If you have a string with xml then this will give you the first tag
var xml = "<foo><bar>......";
var tag = /<(.*?)>/.exec(xml)[1];
alert(tag) // foo
Alternatively you just access the node and retrieves the tagName
Sean Kinsey
2010-06-01 18:51:58
`<?xml version="1.0" encoding="UTF-8" ?><foo><bar/></foo>`
KennyTM
2010-06-01 18:54:14
Are you referring to what 'valid' XML is? If so then be aware that the `<?xml...?>` block is optional..
Sean Kinsey
2010-06-01 19:11:52
@Sean: No, I mean your regex will show `?xml version="1.0" encoding="UTF-8" ?` as the tag name.
KennyTM
2010-06-01 21:24:39