Friday, 27 September 2013

XPath search does not work

XPath search does not work

I try to access an xml file with dom4j. I also tried trough the dom of
org.w3c but this failed in the same way. I have a sample of the xml file
which I try to read below. I try to read the attribute xlink:href from the
element loc but for some reason this always fails. When I try the same
methods on an simple xml file I write myself, it does work. I've been
working on this for days now. Here is my method:
File file = new File("schemas/pfs-2013-04-01-presentation.xml");
SAXReader reader = new SAXReader();
Document document = reader.read(file);
XPath xpath = document.createXPath("//loc");
Map uris = new HashMap();
uris.put("", "http://www.xbrl.org/2003/linkbase");
uris.put("xbrli","http://www.xbrl.org/2003/instance");
uris.put("xlink","http://www.w3.org/1999/xlink");
uris.put("xsi","http://www.w3.org/2001/XMLSchema-instance");
xpath.setNamespaceURIs(uris);
List<Node> nodes = xpath.selectNodes(xpath);
From these 'nodes' I want to read the attributes later on. When I execute
this the List is empty however. This is something do not understand.
Can anyone help me with this please? thanks
<?xml version="1.0" encoding="UTF-8"?>
<linkbase xmlns="http://www.xbrl.org/2003/linkbase"
xmlns:xbrli="http://www.xbrl.org/2003/instance"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xbrl.org/2003/linkbase
http://www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd"
xmlns:presentationAttribute="http://www.nbb.be/be/fr/pfs/presentationAttribute"
>
<roleRef
roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullIdentifyingData"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullIdentifyingData"/>
<roleRef
roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullBalanceSheet"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullBalanceSheet"/>
<roleRef
roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullIncomeStatement"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullIncomeStatement"/>
<roleRef
roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullAppropriationsWithdrawings"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullAppropriationsWithdrawings"/>
<roleRef roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullDisclosures"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullDisclosures"/>
<roleRef
roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullSocialBalanceSheet"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullSocialBalanceSheet"/>
<roleRef
roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullValidationRules"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullValidationRules"/>
<roleRef
roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullManagementReport"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullManagementReport"/>
<roleRef
roleURI="http://www.nbb.be/be/fr/pfs/ci/role/FullAccountantsReport"
xlink:type="simple"
xlink:href="pfs-full-2013-04-01.xsd#FullAccountantsReport"/>
<presentationLink xlink:type="extended"
xlink:role="http://www.nbb.be/be/fr/pfs/ci/role/FullIdentifyingData">
<loc xlink:type="locator"
xlink:href="pfs-2013-04-01.xsd#pfs_IdentifyingData"
xlink:label="IdentifyingData_1" />
<loc xlink:type="locator"
xlink:href="pfs-gcd-2013-04-01.xsd#pfs-gcd_GlobalCommonDocument"
xlink:label="GlobalCommonDocument_2" />
<loc xlink:type="locator"
xlink:href="pfs-gcd-2013-04-01.xsd#pfs-gcd_EntityInformation"
xlink:label="EntityInformation_3" />
<loc xlink:type="locator"
xlink:href="pfs-gcd-2013-04-01.xsd#pfs-gcd_EntityName"
xlink:label="EntityName_4" />
<loc xlink:type="locator"
xlink:href="pfs-gcd-2013-04-01.xsd#pfs-gcd_EntityCurrentLegalName"
xlink:label="EntityCurrentLegalName_5" />

No comments:

Post a Comment