Support Requests item #1769459, was opened at 2007-08-07 08:04
Message generated for change (Comment added) made by nobody
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=216035&aid=1769459&group_id=16035

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Priority: 5
Private: No
Submitted By: Michael (mthenderson)
Assigned to: Nobody/Anonymous (nobody)
Summary: xpath fails to return results

Initial Comment:
I am having a issue using xpath.  We are receiving a file from an external 
vender.  When we use xpath to parse the file, we don’t get any results. 
Below is a brief example.

<?xml version="1.0" encoding="UTF-8"?>
<TXLife Version="2.16.01" xmlns="http://ACORD.org/Standards/Life/2"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://ACORD.org/Standards/Life/2 TXLife2.16.01.xsd">
        <TXLifeRequest>
                <TransRefGUID>abc1234567</TransRefGUID>
        </TXLifeRequest>
</TXLife>



The following code returns no result 
List nodes = doc.selectNodes("//TransRefGUID");

I realize it's due to the default namespace declaration, but the file comes 
from an external vendor and we have not control over it.

Is there a fix for this?  Is there a work around?  We have no control over the 
incoming xml.

Mike Henderson


----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2007-08-07 08:10

Message:
Logged In: NO 

Use DocumentFactory for creating document and set it's namespace map for
XPath:

namespaces.put("default", "http://ACORD.org/Standards/Life/2";);

DocumentFactory documentFactory = DocumentFactory.getInstance();
documentFactory.setXPathNamespaceURIs(namespaces);

reader = new SAXReader(documentFactory);

Than you can use "default" as prefix for your namespace:

List nodes = doc.selectNodes("//default:TransRefGUID");

You can try empty prefix:

namespaces.put("", "http://ACORD.org/Standards/Life/2";);

but I can't remember if this works.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=216035&aid=1769459&group_id=16035

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
dom4j-dev mailing list
dom4j-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to