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

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

I guess we both learned something from this - I didn't know about XPath.

I did notice one thing though. In your first code block you have

{code}
<set field="attributeNode" from-field="document['resource/property[1]/@key']"/>
{code}

returning a single Node. Then in the second code block you have

{code}
<iterate entry="node" list="parameters.document['resource/property']">
{code}

returning a List of Nodes. I understand it's the XPath expression that makes 
the difference between a single Node or a List. I'm wondering if that will 
cause confusion for others. It's not a big deal - just an observation.

Anyways, it would be nice if we could continue to follow the UEL syntax to 
select a Node from a List of Nodes:

{code}
<set field="nodeList" from-field="document['resource/property']"/>
<set field="firstNode" from-field="nodeList[0]"/>
{code}

but don't let that additional enhancement prevent you from committing what you 
have so far.

It looks great to me - go for it!



> 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