dom4j で xml ファイルにアクセスしようとしています。org.w3c の dom も試してみましたが、これも同じように失敗しました。以下に読み込もうとしているxmlファイルのサンプルがあります。要素 loc から属性 xlink:href を読み取ろうとしましたが、何らかの理由でこれは常に失敗します。自分で書いた単純なxmlファイルで同じ方法を試すと、うまくいきます。私はこれに何日も取り組んできました。これが私の方法です:
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);
これらの「ノード」から、後で属性を読み取りたいと思います。ただし、これを実行すると、リストは空です。これが何かわからない。
誰でもこれで私を助けてくれますか? ありがとう
<?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" />