cancel
Showing results for 
Search instead for 
Did you mean: 

XML DOM Javascript

koolalfdev
Champ in-the-making
Champ in-the-making
Hi All,

I am trying to access a avm node which is a xml document and I want to get the contents of the xml in JavaScript like I can do with document.xmlNodeModel in .ftl files. I was wondering if I can do it in javascript as well. I looked at contents in the avm node it did not show the xmlNodeModel reference for that avm node.

Thanks  Smiley Happy
4 REPLIES 4

sbuckle
Champ in-the-making
Champ in-the-making
If you can grab the content of the node then yes, you can process it as XML in JavaScript; Rhino 1.6 and later has built-in support for E4X. For example, you can do something like this in your JavaScript:
var xml = new XML('<your XML string>');‍‍‍
Here's a link to a basic tutorial if you are not familiar with E4X: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_GuideSmiley Tonguerocessing_XML_with_E4X

koolalfdev
Champ in-the-making
Champ in-the-making
Thanks for the response but in the xml to get xml in javascript
<?xml version="1.0" encoding="UTF-8"?> this line posses an error.

Right now I am manipulating the string with javascript code.

how to get rid of this line.

Thanks.

sbuckle
Champ in-the-making
Champ in-the-making
The simplest way is to use substring:

var xmlstr = '<your xml string>';var header = '<?xml version="1.0" encoding="UTF-8"?>';xmlstr = xmlstr.substring(header.length);var xml = new XML(xmlstr);‍‍‍‍‍‍

koolalfdev
Champ in-the-making
Champ in-the-making
Thanks Smiley Happy