Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

Is it possible to use an xpath string on xml within a script activity?

Avatar

Level 1

I'd like to be able to use xpath on an xml rather than E4X, I know E4X works but I'd like to be able to use string expressions.
e.g.

var xml = new XML(
  <root>
    <item count="4"/>
  </root>
);

given the code above I'd like to be able to do something like xml.getValue("//@count").

 

I see that there is a method in the docs that should do what I want however i haven't been able to use it successfully.
https://experienceleague.adobe.com/developer/campaign-api/api/m-DOMElement-getValue.html

 

If anyone could please help I would be extremely grateful.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

 

Doc link isn't accurate here- XML objects in workflows don't have getValue().

 

Here are e4x equivalents for xpaths though, from https://svn.wso2.org/repos/wso2/tags/carbon/0.1alpha/mashup/java/xdocs/e4xquickstart.html:

XPathMeaningE4X Equivalent

element/*

Select all children of element

element.*

element/@*

Select all attributes of element

element.@*

element//descendent

Select all descendents (children, grandchildren, etc.) of element

element..descendent

.. or parent::element

Select the parent of element

element.parent()

xmlns:foo="..."

element/foo:bar

Select the foo:bar child of element where foo is the prefix of a declared namespace

var foo = new Namespace(...);

element.foo::bar

name(element)

Return the full name (including prefix if any) of element

element.name()

local-name(element)

Return the local name of element

element.localName()

namespace-uri(element)

Return the namespace uri (if any) of element

element.namespace()

element/namespace::*

Return the collection of namespaces as an Array of Namespace objects (E4X) or a nodeset of Namespaces nodes (XPath)

element.inScopeNamespaces()

element/processing-instructions(name)

Return the processing instruction children of element with the specified name (if omitted, all are returned).

element.processingInstructions(name)

string(element)

Return the concatenated text nodes of this element and all its descendants

stringValue(element);

stringValue.visible = false;
function stringValue(node) {
    var value = "";
    if (node.hasSimpleContent()) {
        value = node.toString();
    } else {
        for each (var c in node.children()) {
            value += stringValue(c);
        }
    }
    return value;
}

 

xml.getValue("//@count") -> xml..@count 

 

Thanks,

-Jon

View solution in original post

3 Replies

Avatar

Level 1

Hi Jyoti,

I'm well aware E4X syntax works but it won't allow me to use a string expression without using eval. I'm looking for something that allows me to use string expressions.

 

Thanks.

Avatar

Correct answer by
Community Advisor

Hi,

 

Doc link isn't accurate here- XML objects in workflows don't have getValue().

 

Here are e4x equivalents for xpaths though, from https://svn.wso2.org/repos/wso2/tags/carbon/0.1alpha/mashup/java/xdocs/e4xquickstart.html:

XPathMeaningE4X Equivalent

element/*

Select all children of element

element.*

element/@*

Select all attributes of element

element.@*

element//descendent

Select all descendents (children, grandchildren, etc.) of element

element..descendent

.. or parent::element

Select the parent of element

element.parent()

xmlns:foo="..."

element/foo:bar

Select the foo:bar child of element where foo is the prefix of a declared namespace

var foo = new Namespace(...);

element.foo::bar

name(element)

Return the full name (including prefix if any) of element

element.name()

local-name(element)

Return the local name of element

element.localName()

namespace-uri(element)

Return the namespace uri (if any) of element

element.namespace()

element/namespace::*

Return the collection of namespaces as an Array of Namespace objects (E4X) or a nodeset of Namespaces nodes (XPath)

element.inScopeNamespaces()

element/processing-instructions(name)

Return the processing instruction children of element with the specified name (if omitted, all are returned).

element.processingInstructions(name)

string(element)

Return the concatenated text nodes of this element and all its descendants

stringValue(element);

stringValue.visible = false;
function stringValue(node) {
    var value = "";
    if (node.hasSimpleContent()) {
        value = node.toString();
    } else {
        for each (var c in node.children()) {
            value += stringValue(c);
        }
    }
    return value;
}

 

xml.getValue("//@count") -> xml..@count 

 

Thanks,

-Jon