0

I'm putting together a script for InDesign using javascript, and have a settings xml file from which I'd like to pull out a value of a particular node.

I've successfully read in the XML file

var xml = new XML(file.read());

and can easily pull attribute values / node lengths etc, however I'd like to pull the text inside a particular node.

<article>
    <title>This is the title</title>
</article>

I've tried xml.article[0].title but this returns an XML object not the vale. I've tried nodeValue to no success. How do I obtain the actual text?

user3791372
  • 4,445
  • 6
  • 44
  • 78

2 Answers2

0

This did the trick:

xml.article[0].title.toString() 
user3791372
  • 4,445
  • 6
  • 44
  • 78
-2

Its very simple, just searching the stackoverflow should have given you the result

var sXML = "<article><title>This is the title</title></article>";
$( document ).ready( function ()
{
    var xmlDoc = $( sXML );
    xmlDoc.filter( 'article' ).each( function ()
    {
        alert( $( this ).find( 'title' ).text() );
    } );
} );
kvk95
  • 130
  • 2
  • 9