views:

51

answers:

1

This code references the root XML node, adds a FirstXMLObject under it, then adds a few fields under FirstXMLObject:

var myXMLroot = mydocument.xmlElements.item(0);  // The root always exists
var b = myXMLroot.xmlElements.add( "FirstXMLObject");
b.xmlElements.add( "Name", "Bob");
b.xmlElements.add( "Address", "1234 Sesame Lane");

Supposedly, the second parameter to "add" is the value of the field. However, when I drag the associated InDesign tag to a document, nothing shows up.

What method or parameter do I set the value of the XML Element so that it links to InDesign? Is there some book that lists these methods and how to use them using JavaScript?

I was able to get InDesign ExtendScript to load MS ASP.NET MVC 2 JSON serialize products to a single JavaScript variable using eval. Now I need to get those products in the XML structure pane.

A: 

I ended up doing this:

var myXMLroot = mydocument.xmlElements.item(0);  // The root always exists
var b = myXMLroot.xmlElements.add( "FirstXMLObject");
var c = b.xmlElements.add( "Name");
    c.contents = "Bob";
var d = b.xmlElements.add( "Address");
    d.contents = "1234 Sesame Lane";

And this for images (on a Mac):

e.xmlAttributes.add("href", "file://" + 
     varPathToImage.replace(/^.?:\\/i, "G:").replace(/\\/g, ":"));

This for a PC:

e.xmlAttributes.add("href", "file://" + varPathToImage);

And this to determine which one to use:

 if( File.fs == "Windows")
Dr. Zim