[dom4j-dev] [ dom4j-Support Requests-1769459 ] xpath fails to return results
Support Requests item #1769459, was opened at 2007-08-07 17:04
Message generated for change (Comment added) made by filipjirsak
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.
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">
abc1234567
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: Filip Jirsák (filipjirsak)
Date: 2007-08-08 07:41
Message:
Logged In: YES
user_id=1175071
Originator: NO
You should decorate all tag names with namespace prefix:
//x:[EMAIL PROTECTED]//x:Holding[child::x:[EMAIL PROTECTED] =
'3']]/x:Policy/x:Life/x:Coverage/x:LifeParticipant[child::x:[EMAIL
PROTECTED]'18']]/@PartyID]/x:Person/x:LastName
--
Comment By: Michael (mthenderson)
Date: 2007-08-07 23:24
Message:
Logged In: YES
user_id=1862440
Originator: YES
Ok, both of these solutions work for the simpler searches.
However, a number of the xpath statements I need to build are quite
complicated. For example to get the owners last name, I would use the
following.
//[EMAIL PROTECTED]//Holding[child::[EMAIL PROTECTED] =
'3']]/Policy/Life/Coverage/LifeParticipant[child::[EMAIL
PROTECTED]'18']]/@PartyID]/Person/LastName
I tried the following with no result
//x:[EMAIL PROTECTED]//x:Holding[child::[EMAIL PROTECTED] =
'3']]/Policy/Life/Coverage/LifeParticipant[child::[EMAIL
PROTECTED]'18']]/@PartyID]/Person/LastName
Here is a trimmed version of the XML. Please note, I may have numerous
holdings and numerous parties. I need to use the type codes and ids to
relate the two and get the correct name.
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">
Finetre
abc1234567
True
2006-12-07
15:04:15
Finetre
Person
Roberta
Allen
Policy
(Life)
Proposed
Family Income
125
Owner
Holding
Party
Owner
--
Comment By: Mike Skells (mskells)
Date: 2007-08-07 22:16
Message:
Logged In: YES
user_id=258940
Originator: NO
Hi Mike,
As you say the issue is the default namespace - the way around this is to
use an explicit namespace in the xpath query. The prefix in the query has
no bearing in the actual query so the following demo show how to do this
--
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.XPath;
import org.dom4j.io.SAXReader;
import org.dom4j.xpath.DefaultXPath;
public class xp {
public
[dom4j-dev] [ dom4j-Support Requests-1769459 ] xpath fails to return results
Support Requests item #1769459, was opened at 2007-08-07 10:04
Message generated for change (Comment added) made by mthenderson
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.
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">
abc1234567
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: Michael (mthenderson)
Date: 2007-08-07 16:24
Message:
Logged In: YES
user_id=1862440
Originator: YES
Ok, both of these solutions work for the simpler searches.
However, a number of the xpath statements I need to build are quite
complicated. For example to get the owners last name, I would use the
following.
//[EMAIL PROTECTED]//Holding[child::[EMAIL PROTECTED] =
'3']]/Policy/Life/Coverage/LifeParticipant[child::[EMAIL
PROTECTED]'18']]/@PartyID]/Person/LastName
I tried the following with no result
//x:[EMAIL PROTECTED]//x:Holding[child::[EMAIL PROTECTED] =
'3']]/Policy/Life/Coverage/LifeParticipant[child::[EMAIL
PROTECTED]'18']]/@PartyID]/Person/LastName
Here is a trimmed version of the XML. Please note, I may have numerous
holdings and numerous parties. I need to use the type codes and ids to
relate the two and get the correct name.
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">
Finetre
abc1234567
True
2006-12-07
15:04:15
Finetre
Person
Roberta
Allen
Policy
(Life)
Proposed
Family Income
125
Owner
Holding
Party
Owner
--
Comment By: Mike Skells (mskells)
Date: 2007-08-07 15:16
Message:
Logged In: YES
user_id=258940
Originator: NO
Hi Mike,
As you say the issue is the default namespace - the way around this is to
use an explicit namespace in the xpath query. The prefix in the query has
no bearing in the actual query so the following demo show how to do this
--
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.XPath;
import org.dom4j.io.SAXReader;
import org.dom4j.xpath.DefaultXPath;
public class xp {
public static void main(String[] args) throws Exception {
String xml = "" +
"" +
"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\">" +
"" +
"abc1234567" +
"" +
"";
Document doc = new SAXR
[dom4j-dev] [ dom4j-Support Requests-1769459 ] xpath fails to return results
Support Requests item #1769459, was opened at 2007-08-07 15:04
Message generated for change (Comment added) made by mskells
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.
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">
abc1234567
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: Mike Skells (mskells)
Date: 2007-08-07 20:16
Message:
Logged In: YES
user_id=258940
Originator: NO
Hi Mike,
As you say the issue is the default namespace - the way around this is to
use an explicit namespace in the xpath query. The prefix in the query has
no bearing in the actual query so the following demo show how to do this
--
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.XPath;
import org.dom4j.io.SAXReader;
import org.dom4j.xpath.DefaultXPath;
public class xp {
public static void main(String[] args) throws Exception {
String xml = "" +
"" +
"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\">" +
"" +
"abc1234567" +
"" +
"";
Document doc = new SAXReader().read(new StringReader(xml));
XPath xpath = new DefaultXPath("//x:TransRefGUID");
xpath.setNamespaceURIs(Collections.singletonMap("x",
"http://ACORD.org/Standards/Life/2";));
List nodes = xpath.selectNodes(doc);
System.out.println(nodes);
}
}
---
this produces the following output
[EMAIL PROTECTED] [Element: http://ACORD.org/Standards/Life/2 attributes: []/>]]
Mike Skells
--
Comment By: Michael (mthenderson)
Date: 2007-08-07 20:03
Message:
Logged In: YES
user_id=1862440
Originator: YES
Thanks, that did the trick.
Mike
--
Comment By: Nobody/Anonymous (nobody)
Date: 2007-08-07 15: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
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev
[dom4j-dev] [ dom4j-Support Requests-1769459 ] xpath fails to return results
Support Requests item #1769459, was opened at 2007-08-07 10:04
Message generated for change (Comment added) made by mthenderson
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.
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">
abc1234567
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: Michael (mthenderson)
Date: 2007-08-07 15:03
Message:
Logged In: YES
user_id=1862440
Originator: YES
Thanks, that did the trick.
Mike
--
Comment By: Nobody/Anonymous (nobody)
Date: 2007-08-07 10: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
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev
[dom4j-dev] [ dom4j-Support Requests-1769459 ] xpath fails to return results
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.
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">
abc1234567
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev
[dom4j-dev] [ dom4j-Support Requests-1769459 ] xpath fails to return results
Support Requests item #1769459, was opened at 2007-08-07 10:04
Message generated for change (Tracker Item Submitted) made by Item Submitter
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.
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">
abc1234567
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
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev
