phax / ph-ubl

Java library for reading and writing UBL 2.0, 2.1, 2.2, 2.3 and 2.4 documents

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[UBL2.1] Unable to add UBLDocumentSignatures in "UBLExtentions > UBLExtention > ExtensionContent"

LeeWC-13 opened this issue · comments

Hi Phax, thank you for sharing this library.
I'm creating a InvoiceType with DocumentSignatures in UBLExtension, I'm getting error while adding the signatures in extension content.
Can you help to explain more about the validation error or any suggestion to fix this error?

Java Code:
UBLDocumentSignaturesType signatures = new UBLDocumentSignaturesType();
signatures.addSignatureInformation(signatureInfo);
extensionContent.setAny(signatures);
ublExtension.setExtensionURI("urn:oasis:names:specification:ubl:dsig:enveloped:xades");
ublExtension.setExtensionContent(extensionContent);
ublExtensions.addUBLExtension(ublExtension);
inv.setUBLExtensions(ublExtensions);

Validation Result:
[Text=cvc-complex-type.2.4.b: The content of element 'cec:ExtensionContent' is not complete. One of '{WC[##other:"urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"]}' is expected.]

Target Format:

<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
<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>
...
</sac:SignatureInformation>
</sig:UBLDocumentSignatures>
</ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>

I created some sample code to run your example.
Basically what you need to do, is to pass in a org.w3c.dom.Element into extensionContent.setAny (...);. So you need to explicitly marshall the extension content before adding it in. Passing in the domain object will not work.
hth

Thank you very much, able to acheive my target now.