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.
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies