[ 
https://issues.apache.org/jira/browse/OFBIZ-2397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12705006#action_12705006
 ] 

Adrian Crum commented on OFBIZ-2397:
------------------------------------

On a side note - the ELResolver class is a part of the javax.el package. It's 
an API. JUEL is an implementation of the javax.el API. I'm not being picky, I'm 
just clarifying that for anyone who might be "listening in."


> Implement a custom JUEL resolver for performing XPath queries on DOM Nodes
> --------------------------------------------------------------------------
>
>                 Key: OFBIZ-2397
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2397
>             Project: OFBiz
>          Issue Type: New Feature
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Scott Gray
>            Assignee: Scott Gray
>         Attachments: XPath.patch
>
>
> In order to make XML easy to read using simple methods I've implemented a 
> custom JUEL ELResolver that handles string properties for objects 
> implementing org.w3c.dom.Node and org.apache.xerces.dom.NodeImpl.  It takes 
> the String and compiles it into an XPathExpression which is then evaluated 
> against the base Node.  The JUEL evaluation returns either null, a single 
> Node or a NodeList depending on the result of the XPath evaluation.
> Type conversion is handled using the set operation like so:
> {code}
> // Get the key attribute node from the first property element, note no type 
> is specified so no conversion takes place
> <set field="attributeNode" 
> from-field="document['resource/property[1]/@key']"/>
> // ObjectType.simpleTypeConvert calls getTextContent on the node, if the 
> target type is anything other than a string it calls simpleTypeConvert again 
> using the string
> // Get the value of the attribute key from the first property element
> <set field="attributeValue" 
> from-field="document['resource/property[1]/@key']" type="String"/>
> // If the key value were an Integer you could do this, the conversion would 
> be node.getTextContent -> String -> Integer
> <set field="attributeValue" 
> from-field="document['resource/property[1]/@key']" type="Integer"/>
> {code}
> I've also added support for NodeList to the iterate tag so that you can do 
> this:
> {code:xml}
> <iterate entry="node" list="parameters.document['resource/property']">
>     <log level="always" message="Property Key: ${node['@key']}"/>
>     <log level="always" message="First Value: ${node['value[1]']}"/>
> </iterate>
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to