如何使用 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.JdbcOdbc...