2013-09-27 3 views
0

dom4j를 사용하여 xml 파일에 액세스하려고합니다. 나는 또한 org.w3c의 돔을 시도했지만 같은 방식으로 실패했다. 아래에서 읽으려는 xml 파일의 샘플이 있습니다. 요소의 loc에서 xlink : href 속성을 읽으려고하지만 어떤 이유로이 방법은 항상 실패합니다. 간단한 xml 파일에서 같은 방법을 시도해 볼 때 나 자신을 쓴다. 나는 며칠 동안이 일을 해왔다. 내 방법은 다음과 같습니다.XPath 검색이 작동하지 않습니다.

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); 

이 'nodes'에서 나는 나중에 속성을 읽고 싶습니다. 그러나 이것을 실행하면 List는 비어 있습니다. 이것은 이해가 안되는 것입니다.

누구든지 나를 도와 줄 수 있습니까? 감사

<?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" /> 
+0

빈 접두사를 설정할 수 있습니까? XPath에서는 "no URI"네임 스페이스를 나타내고 다른 네임 스페이스에는 접두사가 있어야합니다. – choroba

답변

0

기본 네임 스페이스를 사용하지 않는 때문에, XPath는 당신의 "LOC"노드를 찾는 방법을 알 수 없습니다. "loc"노드에 접두어를 붙이고 동일한 접두어에 사용할 적절한 네임 스페이스를 업데이트해야합니다. 자세한 내용은 다음을 참조하십시오. XPath and Default Namespace handling

관련 문제