Frederik Witte
Frederik Witte

Reputation: 1345

Don't Add Indesign Tags to the root element?

following code example:

var myDocument = app.documents.add();
var myTextFrame = myDocument.pages.item(0).textFrames.add();
myTextFrame.geometricBounds = ["6p", "6p", "24p", "24p"];
myTextFrame.contents = "Hello World!";

myBounds = myTextFrame.geometricBounds;


var myX = "" + myBounds[1];
var myY = "" + myBounds[0];

var myTag = myDocument.xmlTags.add("text-area");

var myXMLElement =  myDocument.xmlElements.item(0).xmlElements.add(myTag, myTextFrame);
myXMLElement.xmlAttributes.add("x", myX);
myXMLElement.xmlAttributes.add("y", myY);

This will give out the following xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root><text-area x="25.4" y="25.4000000000001">Hello World!</text-area></Root>

Can I somehow not show the root tag? Delete it or don't let it show up in the .xml? I searched for different keywords but I couldn't find the solution to this.

Thanks in advance.

Upvotes: 2

Views: 596

Answers (1)

Josh Voigts
Josh Voigts

Reputation: 4132

Every document has a new root element by default. If you grab the first xmlElement, that's the root element. Here's an example of the changes you would make to have text-area be the root element:

var myDocument = app.documents.add();
var myTextFrame = myDocument.pages[0].textFrames.add();
myTextFrame.geometricBounds = ["6p", "6p", "24p", "24p"];
myTextFrame.contents = "Hello World!";

var myRootElem = myDocument.xmlElements[0];
myRootElem.markupTag.name = "text-area";

var myBounds = myTextFrame.geometricBounds;
var myX = "" + myBounds[1];
var myY = "" + myBounds[0];

myRootElem.xmlAttributes.add("x", myX);
myRootElem.xmlAttributes.add("y", myY);

myTextFrame.markup(myRootElem);

Upvotes: 2

Related Questions