I am using JDOM and Jaxen together but I fail to get the desired result. I'm
unsure whether it's my lack of knowledge in this area or a bug.

I have the following piece of code:-

1.  public class TestJaxen{
2.  public static void test(String fileName, String outerXPathExpression,
String innerXPathExpression) {
3.  try{
4.  SAXBuilder builder = new SAXBuilder();
5.  Document doc = builder.build( fileName );
6.  XPath xpath = new JDOMXPath( outerXPathExpression );
7.  List results = xpath.selectNodes(doc);
8.  Iterator iterator = results.iterator();
9.  Navigator navigator = xpath.getNavigator();
10. while (iterator.hasNext()) {
11. Object result = iterator.next();
12. XPath xpathInner = new JDOMXPath( innerXPathExpression );
13. Object resultsInner = xpathInner.selectSingleNode(result);
14. Navigator navigatorInner = xpathInner.getNavigator();
15. String valueInner = StringFunction.evaluate(resultsInner,
navigatorInner);
16. System.out.println("valueInner: " + valueInner );
17. }
18. }
19. }

For reference I pass "dsp_f9_21.xml" "TRADING/DOCUMENT"
"S.SG01/S.RFF.Reference/C.C506.Reference" as parameters where the file is as
detailed:-

<?xml version = "1.0" encoding = "UTF-8"?>
<TRADING>    
        <DOCUMENT DocNumber = "1" DocType = "Despatch Advice">        
                <S.SG01>            
                        <S.RFF.Reference>                
                                <C.C506.Reference>Hello</C.C506.Reference>

                        </S.RFF.Reference>                     
                </S.SG01>        
        </DOCUMENT>
        <DOCUMENT DocNumber = "2" DocType = "Despatch Advice">        
                <S.SG01>            
                        <S.RFF.Reference>                
                                <C.C506.Reference>Hello2</C.C506.Reference>

                        </S.RFF.Reference>                       
                </S.SG01>        
        </DOCUMENT>
</TRADING>

Essentially, there are a number of DOCUMENTs in each file and I want to
process the data held within each DOCUMENT. My strategy was to XPath the
file, using "TRADING/DOCUMENT", passing the node-set to a List as in line#7.
Subsequently, I would iterate through the List and process each DOCUMENT in
turn using the second XPath expression,
"S.SG01/S.RFF.Reference/C.C506.Reference", on the result from the first
execution of XPath to achieve this.

Document ------> Node set ---------> Node ------> value
          xpath             iterate        xpath

I hope this makes sense. I managed to do this with Oracle's XDK before
giving up with their bug-ridden implementation.

Any thoughts or help would be appreciated.

Paul Scullion  
+++++ The Forestry Commission's computer systems may be monitored and
communications carried out on them recorded, to secure the effective
operation of the system and for other lawful purposes. +++++


-------------------------------------------------------
This sf.net email is sponsored by: Jabber - The world's fastest growing 
real-time communications platform! Don't just IM. Build it in! 
http://www.jabber.com/osdn/xim
_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to