[ 
https://issues.apache.org/jira/browse/OFBIZ-2397?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Scott Gray closed OFBIZ-2397.
-----------------------------

       Resolution: Fixed
    Fix Version/s: SVN trunk

Anyone using the XPath will have to know the grammar of the xml their working 
with and should know whether a particular expression will return a single node 
or a list of nodes.  They would need to know that regardless of what language 
they are using to execute the expressions so it's not a problem unique to this 
situation.  Besides there are a ton of online XPath expression test beds where 
you can paste your xml and try out different queries on it.

I liked your idea about indexing into a NodeList but the problem is that 
NodeList is it own interface and doesn't implement Node or NodeImpl which means 
I would need to write another resolver or try and shoehorn it into this one.  I 
didn't feel like doing either of those things right now, but still it would be 
nice at some point.

Anyways thanks for the feedback/review, committed in r770915

> 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
>             Fix For: SVN trunk
>
>         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