Two questions about UBLExtensionType
pdeleg opened this issue · comments
Hi Philip,
Thank you for your great library.
If have to use a specific extension in this place :
<cec:UBLExtensions>
<cec:UBLExtension>
<cec:ExtensionContent>
<aife:FactureExtension> <!-- this one -->
<aife:CategoryCode>...
-
So, if I understand the code, I must derive the CodeType class as made in HazardousCategoryCodeType and renamed it ?
-
How, can I add the nameSpace "xmlns:aife="urn:AIFE:Facture:Extension" in the output of the UBL21Writer ?
Hi! Thanks.
ad 1) I'm not sure what you want to do. Do you want to add content to a cec:ExtensionContent
element? If so, simple use the setAny
method of class ExtensionContentType
to set the aife:FactureExtension
as a DOM Element (So build your structure in memory and than set it).
ad 2) By default the default namespaces are present (see UBL21NamespaceContext
). Mabye the simplest things is to do sthg. like this (assuming you want to write an invoice):
UBL21WriterBuilder <InvoiceType> aBuilder = UBL21Writer.invoice ();
MapBasedNamespaceContext aCtx = (MapBasedNamespaceContext) aBuilder.getNamespaceContext ();
aCtx.addMapping ("aife", "urn:AIFE:Facture:Extension");
alternatively you can build the complete namespace context as done in UBL21WriterBuilder
constructor but I'd prefer the outlined version.
hth, Philip
Hi Philip,
Thanks for yours replies.
for the 2) I think that will be good.
For the 1)
I don't have others information than this model :
<cec:UBLExtensions>
<cec:UBLExtension>
<cec:ExtensionContent>
<aife:FactureExtension>
<aife:CategoryCode>XX</aife:CategoryCode>
</aife:FactureExtension>
</cec:ExtensionContent>
</cec:UBLExtension>
</cec:UBLExtensions>
With a given enum for the XX value.
I don't have any others informations about this aife:FactureExtension.
I have seen the setAny method of class ExtensionContentType.
I thought I could create a class that extends the CodeType class and then pass it with in the setAny method.
In another way, can you give me a sample example code for doing the DOM element ?
Pierre
Hi Pierre!
I added example in the class CreateInvoiceFromScratchFuncTest
that shows how to create an extension and how to add it.
On my machine the output is this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Invoice xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<cec:UBLExtensions>
<cec:UBLExtension>
<cec:ExtensionContent>
<FactureExtension xmlns="urn:AIFE:Facture:Extension">
<CategoryCode>XX</CategoryCode>
</FactureExtension>
</cec:ExtensionContent>
</cec:UBLExtension>
</cec:UBLExtensions>
<cbc:ID>Dummy Invoice number</cbc:ID>
<cbc:IssueDate>2017-05-23</cbc:IssueDate>
<cac:AccountingSupplierParty />
<cac:AccountingCustomerParty />
<cac:LegalMonetaryTotal>
<cbc:PayableAmount currencyID="EUR">10</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>1</cbc:ID>
<cbc:LineExtensionAmount currencyID="EUR">10</cbc:LineExtensionAmount>
<cac:Item />
</cac:InvoiceLine>
</Invoice>
Hi Philip,
I have the same result than you on my machine.
The new test work perfectly for DOM 's extension, but not for the add of the name Space in the head part.
Also, I hope this syntax will be OK : FactureExtension xmlns="urn:AIFE:Facture:Extension"
Thank you very mutch.
Pierre
Hi Pierre!
Glad it works for you.
From an XML point of view, this is identical - so I see no problem!
Good luck :)