DOM4J
Return to Developer Support
DOM4J is an open source XML library used by EditMe to provide XML capabilities to Layout scripts. While typical layouts do not need to access the XML at this level, DOM4J provides another option for advanced developers looking to work with XML data in a structured way.
Access to DOM4J is provided via Document objects passed to JavaScript via Mozilla's Rhino JavaScript engine. Aside from the examples provided on this page, full documentation of DOM4J is outside the scope of this web site. Please see the DOM4J web site for full API documentation. In particular, the API documentation of the Document, Node and Element interfaces should be of interest.
Using DOM4J in EditMe
The following example shows how to set the content of a tag by ID in a layout using XPATH:
<script type="text/vnd.editme.js.pre"><![CDATA[
var setme = layout.selectSingleNode("//*[@id='setme']");
setme.text = setme.name + ' tag text set in pre-press script.';
}
]]>
<p id="setme"></p>
Result:
<p id="setme">p tag text set in pre-press script.</p>
In order to use the DocumentHelper class, you need to access it as follows. Here is an example that creates a new Document instance with a root element named "root":
var newDoc = Packages.org.dom4j.DocumentHelper.createDocument();
newDoc.rootElement = Packages.org.dom4j.DocumentHelper.createDefaultElement('root');
As EditMe expands the capabilities of layout scripting, DOM4J will prove useful for managing XML data in Page content. This documentation will be updated in the future with examples of how this and other tasks are accomplished.