微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 Xpath 转换

如何解决如何使用 Xpath 转换

我正在尝试使用 xades4j 对 UBL2.1 进行签名,但我需要从被烧毁的标签中排除一些标签。 我使用了 XPathTransform,但结果摘要无效。

enter image description here

这是我要签署的 UBL 文档(为简单起见,不是完整的文档)

<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <ext:UBLExtensions>
      <ext:UBLExtension>
         <ext:ExtensionContent>
            <sig:UBLDocumentSignatures xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2" xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2">
               <sac:Signatureinformation>
                  <cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID>
                  <sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID>
               </sac:Signatureinformation>
            </sig:UBLDocumentSignatures>
         </ext:ExtensionContent>
      </ext:UBLExtension>
   </ext:UBLExtensions>
   <cbc:ProfileID>reporting:1.0</cbc:ProfileID>
   <cbc:ID>20210000011041000001</cbc:ID>
   <cbc:UUID>7c0925c8-5536-4b73-aeca-e833f3f78b3c</cbc:UUID>
   <cbc:IssueDate>2021-03-14</cbc:IssueDate>
   <cbc:InvoiceTypeCode name="01000">380</cbc:InvoiceTypeCode>
   <cbc:Note>Some Notes</cbc:Note>
   <cbc:DocumentCurrencyCode>USD</cbc:DocumentCurrencyCode>
   <cbc:TaxCurrencyCode>USD</cbc:TaxCurrencyCode>
   <cac:OrderReference />
   <cac:BillingReference>
      <cac:InvoiceDocumentReference />
   </cac:BillingReference>
   <cac:ContractDocumentReference />
   <cac:AdditionalDocumentReference>
      <cbc:ID>ICV</cbc:ID>
      <cbc:UUID>20210000011041000001</cbc:UUID>
   </cac:AdditionalDocumentReference>
   <cac:AdditionalDocumentReference>
      <cbc:ID>PIH</cbc:ID>
      <cac:Attachment>
         <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">X+zrZv/IbzjZUnhsbWlsecLbwjndTpG0ZynXOif7V+k=</cbc:EmbeddedDocumentBinaryObject>
      </cac:Attachment>
   </cac:AdditionalDocumentReference>
   <cac:AdditionalDocumentReference>
      <cbc:ID>QR</cbc:ID>
      <cac:Attachment>
         <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">AUrYp9mE2LTYsdmD2Kkg2KfZhNi52LHYqNmK2Kkg2KfZhNmK2YXZhtmK2Kkg2YTZhNin2LPZhdmG2Kog2KfZhNmF2K3Yr9mI2K/YqQIJMTAwMzMxMDMzAxMyMDIxLTAzLTE0MDA6MDA6MDBaBAY0MjU0MDAFATAGQDIyMjk5YjQ0MTU2MDQ0MjYyMzU0YjkzZThhZjNjZThlMjFkNjRjNWVkZWYyZTkxMjk3OTMzNjllM2Y1YmE1MWEHBUVDRHNhWpWNMRzpzfaMmZhfH4APF155H+Fp5LU9xW0umMbEoS47hWKjcYlakCn6Xhx7Ok6iDSN4syJQVaWfAwmARtM1nw==</cbc:EmbeddedDocumentBinaryObject>
      </cac:Attachment>
   </cac:AdditionalDocumentReference>
   <cac:Signature>
      <cbc:ID>urn:oasis:names:specification:ubl:signature:Invoice</cbc:ID>
      <cbc:SignatureMethod>urn:oasis:names:specification:ubl:dsig:enveloped:xades</cbc:SignatureMethod>
   </cac:Signature>
</Invoice>

我想从签名中排除这些元素:

//ancestor-or-self::ext:UBLExtensions
//ancestor-or-self::cac:Signature
//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR']

所以,我使用了以下 xpath 变换

DataObjectDesc obj = new DataObjectReference("")
                .withTransform(new XPathTransform("not(//ancestor-or-self::ext:UBLExtensions)"))
                .withTransform(new XPathTransform("not(//ancestor-or-self::cac:Signature)"))
                .withTransform(new XPathTransform("not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])"))
                .withDataObjectFormat(new DataObjectFormatProperty("text/xml"));

然而,结果摘要无效。

提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?