EasyManua.ls Logo

Adobe 0046100128056 - InDesign - Mac - Creating Tables Using XML Rules

Adobe 0046100128056 - InDesign - Mac
209 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
CHAPTER 13: XML Rules Creating Tables using XML Rules 203
//Creates a new text frame at the top of the page to contain the "type" XML element.
function ProcessType(){
this.name = "ProcessType";
this.xpath = "/devices/device/type";
this.apply = function(myElement, myRuleProcessor){
var myDocument = app.documents.item(0);
with(myElement){
var myBounds = myGetBounds(myDocument, myDocument.pages.item(-1));
myBounds = [myBounds[0]-24, myBounds[1], myBounds[0], myBounds[2]];
var myTextFrame = placeIntoFrame(myPage, myBounds);
applyParagraphStyle(myDocument.paragraphStyles.item("DeviceType"));
myTextFrame.textFramePreferences.insetSpacing = [6, 6, 6, 6];
myTextFrame.fillColor = myDocument.swatches.item("Red")
}
return true;
}
}
Creating Tables using XML Rules
You can use the convertElementToTable method to turn an XML element into a table. This method has a
limitation in that it assumes that all of the XML elements inside the table conform to a very specific set of
XML tags—one tag for a row element; another for a cell, or column element. Typically, the XML data we
want to put into a table does not conform to this structure: it is likely that the XML elements we want to
arrange in columns use heterogeneous XML tags (price, part number, etc.).
To get around this limitation, we can “wrap” each XML element we want to add to a table row using a
container XML element, as shown in the following script fragments (see XMLRulesTable). In this example, a
specific XML rule creates an XML element for each row.
function ProcessDevice(){
this.name = "ProcessDevice";
this.xpath = "//device[@type = 'VCO']";
this.apply = function(myElement, myRuleProcessor){
var myNewElement = myContainerElement.xmlElements.add(
app.documents.item(0).xmlTags.item("Row"));
return true;
}
}
Successive rules move and format their content into container elements inside the row XML element.

Table of Contents