OpenWGA 7.9 - TMLScript reference

WGA » WGA.Xml
Method :

parse([xmlText [, url]])

On object WGA.Xml
Usage Parses XML text and returns a DOM document object for it
Description

This function uses the Java XML Parser Dom4J to parse the given XML text and returns its DOM document object of class org.dom4j.Document.

For backward compatibility there still is a global function "parseXML()" available whose use is discouraged since OpenWGA 5.3.

Parameters xmlText (String, optional):

XML text to be parsed. Omit to create an empty DOM document.

url (String, optional):

An URL which should be used to resolve relative references in the XML text, like a DOCTYPE reference.

Return value Java object of type org.dom4j.Document
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
    portletevent
Examples Example XML to parse:

<config>
  <cols>
    <col title="ID">CompanyID</col>
    <col title="Firmenname">companyName</col>
    <col title="ZIP">companyMainZip</col>
    <col title="City">companyCity</col>
    <col title="Phone">companyPhone</col>
  </cols>
</config>


Example for parsing this XML, selecting all <col> nodes and setting the resulting list as WebTML variable:

<tml:script>
var doc = WGA.Xml.parse(theXML);
cols =  doc.selectNodes("/config/cols/col")
</tml:script>


Iterating over the node objects with a <tml:foreach> tag. We use TMLScript to extract the text of the ID attribute and the <col> tag itself:

<tml:foreach type="itemvalue" item="cols" currentvalue="col">
  <td>
    <tml:script expression="col.selectSingleNode('@title').getText()"/>
  </td>
  <td>
    <tml:script expression="col..getText()"/>
  </td>
</tml:foreach>