Cernunnos Manual


${parseXml()}

Description:

Parses an XML Document from the specified LOCATION and returns the root element. The identified resource must be parsable XML.

This task leverages the ResourceHelper API and is a replacement for ${doc}, which will not use that API for reasons of backward compatability.

Reagents:

Name XPath Description Reagent Type Expected Type Required
CONTEXT @context Optional context from which missing elements of the LOCATION will be inferred if it is relative. The default is the value of the 'Attributes.CONTEXT' request attribute (if present) or the directory from which Java is executing (otherwise). PHRASE java.lang.String No
LOCATION descendant-or-self::text() Optional location of a resource; if omitted, the value of the 'Attributes.LOCATION' request attribute will be used. LOCATION may be a filesystem path or a URL, and may be absolute or relative; if a relative value is provided, it will be resolved based on the value of CONTEXT. PHRASE java.lang.String No
CACHE @cache A shared Map to cache items in. The default is the value of the 'Attributes.CACHE' request attribute. PHRASE java.util.Map No
CACHE_MODEL @cache-model Specify either NONE, ONE, or ALL. PHRASE java.lang.String No
ENTITY_RESOLVER @entity-resolver Optional org.xml.sax.EntityResolver to use in document parsing. By default, this phrase looks for an EntityResolver instance under the request attribute 'XmlAttributes.ENTITY_RESOLVER' and will use it if present. PHRASE org.xml.sax.EntityResolver No

Examples:

Parses the 'books.xml' document, adds a '<book>' child element, places a comment before the '<book>' element, then writes the file back to the same location:

 
       
        <with-attribute key="Attributes.NODE" value="${parseXml(example.xml)}"> 
          <append-node> 
            <book author="George Eliot"> 
              <title>Middlemarch</title> 
            </book> 
          </append-node>  
          <prepend-node node="${commentNode(This is a great book!)}" sibling="${singleNode(book)}"/>  
          <write-document file="books.xml"/> 
        </with-attribute> 
       
    

Parses a document from the resource at 'properties/db/data.xml', creates a node list from the expression '//table/name', and writes the text value of each node to System.out:

 
       
        <node-iterator source="${parseXml(properties/db/data.xml)}" xpath="//table/name"> 
          <echo-ln>${valueOf(.)}</echo-ln> 
        </node-iterator>