Expand my Community achievements bar.

Can Xpath be used in LiveCycle Designer ES?

Avatar

Former Community Member

Is it possible to use xpath in LiveCycle Designer ES?

Thanks.

2 Replies

Avatar

Level 10

Hi Capiono,

If you are trying to use XPaths in the PDF there is a an applyXPath method available in the Acrobat API, documented in js_api_reference.pdf which is part of the Acrobat X SDK available at http://www.adobe.com/devnet/acrobat/sdk/eula.html or in the Acrobat 8 version directly at http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.p...

So if my form had some xml like;


<formData>
  ...

    <requestId name="RequestId">1263678</requestId>

  ...

</formData>
  
The following will display 1263678 on the console;


console.println(XMLData.applyXPath($data, '//*[@name = "RequestId"]').item(0).value);

That is the value of the first element with a name attribute of RequestId.


I’ve never got this method to work with namespaces and the context is not what I would expect, in this example the root should be $data, but it is still possible to pick up elements from the XFA template.  This is one reason why the XPath expressions I used ended up being more complicated than they could have been, like the one above.


So I stick with SOM expression, but for simple relative XPaths you can use the following to convert to a SOM;


// Attempt to turn a relative XPath into a relative SOM expression
// e.g. ../../clientId/text()  becomes  parent.parent.clientId
function xpathToSom(xpath)
{
    xpath = stripNamespacePrefixes(xpath);
    xpath = xpath.replace(/\.\.\//g, "parent.");
    xpath = xpath.replace(/\/text\(\)/, "");
    xpath = xpath.replace(/\//g, ".");
    return xpath;
}

// Strip all namespace prefixes from an xpath expression
// e.g. /default:collections/default:collection/@reportingPeriod
//       will become
// 
/collections/collection/@reportingPeriod
function stripNamespacePrefixes(xpath)
{
    return xpath.replace(/\/\w*?:/g, "/");
}

This is far from a general routine but maybe somewhere to start.

Bruce