Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two questions about UBLExtensionType #10

Closed
pdeleg opened this issue May 22, 2017 · 5 comments
Closed

Two questions about UBLExtensionType #10

pdeleg opened this issue May 22, 2017 · 5 comments
Assignees
Labels

Comments

@pdeleg
Copy link

pdeleg commented May 22, 2017

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>...
  1. So, if I understand the code, I must derive the CodeType class as made in HazardousCategoryCodeType and renamed it ?

  2. How, can I add the nameSpace "xmlns:aife="urn:AIFE:Facture:Extension" in the output of the UBL21Writer ?

@phax phax self-assigned this May 22, 2017
@phax phax added the question label May 22, 2017
@phax
Copy link
Owner

phax commented May 22, 2017

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

@pdeleg
Copy link
Author

pdeleg commented May 23, 2017

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

phax added a commit that referenced this issue May 23, 2017
@phax
Copy link
Owner

phax commented May 23, 2017

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>

@pdeleg
Copy link
Author

pdeleg commented May 24, 2017

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

@pdeleg pdeleg closed this as completed May 24, 2017
@phax
Copy link
Owner

phax commented May 24, 2017

Hi Pierre!
Glad it works for you.
From an XML point of view, this is identical - so I see no problem!
Good luck :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants