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

UBL 2.1 unused namespace #25

Closed
patricksan opened this issue Mar 5, 2020 · 14 comments
Closed

UBL 2.1 unused namespace #25

patricksan opened this issue Mar 5, 2020 · 14 comments
Assignees

Comments

@patricksan
Copy link

patricksan commented Mar 5, 2020

Dear,

First of all, thanks for your library.

I'm generating one invoice, but I noticed that one namespace is added without being used in the xml:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" 
          xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
          xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
          xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
    <cbc:UBLVersionID>2.1</cbc:UBLVersionID>
    ....
    ....
    
</Invoice>

The xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" is added as namespace, but there is no reference of cec in the xml.

I'm saving the file using these lines:

var status = UBL21Writer.invoice().write(ublInvoice, file);

Is that a bug?

I'm using: JAVA 11 with ph-ubl 6.2.0

Thank you

@patricksan
Copy link
Author

patricksan commented Mar 5, 2020

@phax, I tried this, but it didn't work:

MapBasedNamespaceContext context = UBL21NamespaceContext.getInstance().getClone();
context.removeMapping("urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
writer.setNamespaceContext(context);

var status = writer.write(ublInvoice, file);

Also this:

final MapBasedNamespaceContext context = UBL21NamespaceContext.getInstance().getClone();
context.clear();
context.addDefaultNamespaceURI("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
context.addMapping("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
context.addMapping("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
writer.setNamespaceContext(context);

var status = writer.write(ublInvoice, file);

@patricksan
Copy link
Author

links to #10

@phax phax self-assigned this Mar 5, 2020
@phax phax added the question label Mar 5, 2020
@phax
Copy link
Owner

phax commented Mar 5, 2020

Try

MapBasedNamespaceContext context = UBL21NamespaceContext.getInstance().getClone();
context.removeMapping("cec");
writer.setNamespaceContext(context);

@patricksan
Copy link
Author

Thanks @phax
I get this exception:

Caused by: java.lang.IllegalStateException: Internal inconsistency removing 'cec' and 'urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2'
	at com.helger.xml.namespace.MapBasedNamespaceContext.removeMapping(MapBasedNamespaceContext.java:244)

I tried to use getInstance() instead of getInstance().getClone(). It works in the sense to remove the cec namespace but it adds another one:

xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"

phax added a commit that referenced this issue Mar 5, 2020
phax added a commit that referenced this issue Mar 5, 2020
@phax
Copy link
Owner

phax commented Mar 5, 2020

Okay, I can now reproduce the internal error - I will look at this one separately.
Basically: never modify the singleton UBL21NamespaceContext.getInstance() - only modify clones.

The system adds the ns2 prefix most likely, because your UBL contains an element that needs the urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2 namespace URI....?
Can you paste the full document here?

@patricksan
Copy link
Author

Thanks @phax for the support.

The file doesn't contain the ns2. You can see the file here:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
         xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
         xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
         xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
    <cbc:UBLVersionID>2.1</cbc:UBLVersionID>
    <cbc:ID>2024025255</cbc:ID>
    <cbc:UUID>861dbf17-19a9-4795-b732-004dba0d93cd</cbc:UUID>
    <cbc:IssueDate>2020-01-17</cbc:IssueDate>
    <cbc:DueDate>2020-02-16</cbc:DueDate>
    <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
    <cbc:Note>note</cbc:Note>
    <cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
    <cac:InvoicePeriod>
        <cbc:StartDate>2020-01-01</cbc:StartDate>
        <cbc:EndDate>2020-01-31</cbc:EndDate>
    </cac:InvoicePeriod>
    <cac:AccountingSupplierParty>
        <cac:Party>
            <cac:PartyIdentification>
                <cbc:ID schemeID="BE:VAT">BE123456789012</cbc:ID>
            </cac:PartyIdentification>
            <cac:PartyName>
                <cbc:Name>Fake Name</cbc:Name>
            </cac:PartyName>
            <cac:PartyLegalEntity>
                <cac:RegistrationAddress>
                    <cbc:StreetName>streetName</cbc:StreetName>
                    <cbc:CityName>cityName</cbc:CityName>
                    <cbc:PostalZone>postalZone</cbc:PostalZone>
                </cac:RegistrationAddress>
            </cac:PartyLegalEntity>
            <cac:Contact>
                <cbc:Name>Name example</cbc:Name>
                <cbc:Telephone>0032478989497</cbc:Telephone>
                <cbc:Telefax>0032478989498</cbc:Telefax>
                <cbc:ElectronicMail>[email protected]</cbc:ElectronicMail>
            </cac:Contact>
        </cac:Party>
    </cac:AccountingSupplierParty>
    <cac:AccountingCustomerParty>
        <cac:Party>
            <cac:PartyIdentification>
                <cbc:ID schemeID="BE:VAT">BE0438700000</cbc:ID>
            </cac:PartyIdentification>
            <cac:PartyName>
                <cbc:Name>XXXXXXX</cbc:Name>
            </cac:PartyName>
            <cac:Language>
                <cbc:ID/>
            </cac:Language>
            <cac:PartyLegalEntity>
                <cac:RegistrationAddress>
                    <cbc:StreetName>XXXXXX 17</cbc:StreetName>
                    <cbc:CityName>XXXXXX</cbc:CityName>
                    <cbc:PostalZone>2900</cbc:PostalZone>
                </cac:RegistrationAddress>
            </cac:PartyLegalEntity>
        </cac:Party>
    </cac:AccountingCustomerParty>
    <cac:Delivery>
        <cbc:ActualDeliveryDate>2020-01-01</cbc:ActualDeliveryDate>
        <cac:DeliveryAddress>
            <cbc:StreetName>XXXXXX</cbc:StreetName>
            <cbc:CityName>XXXXXX</cbc:CityName>
            <cbc:PostalZone>2070</cbc:PostalZone>
        </cac:DeliveryAddress>
    </cac:Delivery>
    <cac:PaymentMeans>
        <cbc:PaymentMeansCode>31</cbc:PaymentMeansCode>
        <cbc:PaymentDueDate>2020-02-16</cbc:PaymentDueDate>
        <cac:PayeeFinancialAccount>
            <cbc:ID schemeName="IBAN">BE34409000000000</cbc:ID>
        </cac:PayeeFinancialAccount>
    </cac:PaymentMeans>
    <cac:TaxTotal>
        <cbc:TaxAmount currencyID="EUR">194.05</cbc:TaxAmount>
        <cac:TaxSubtotal>
            <cbc:TaxableAmount currencyID="EUR">924.05</cbc:TaxableAmount>
            <cbc:TaxAmount currencyID="EUR">194.05</cbc:TaxAmount>
            <cac:TaxCategory>
                <cbc:ID schemeID="UNCL5305">S</cbc:ID>
                <cbc:Percent>21</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:TaxCategory>
        </cac:TaxSubtotal>
    </cac:TaxTotal>
    <cac:LegalMonetaryTotal>
        <cbc:LineExtensionAmount currencyID="EUR">924.05</cbc:LineExtensionAmount>
        <cbc:TaxExclusiveAmount currencyID="EUR">924.05</cbc:TaxExclusiveAmount>
        <cbc:TaxInclusiveAmount currencyID="EUR">194.05</cbc:TaxInclusiveAmount>
        <cbc:PayableAmount currencyID="EUR">1118.1</cbc:PayableAmount>
    </cac:LegalMonetaryTotal>
    <cac:InvoiceLine>
        <cbc:ID>1</cbc:ID>
        <cbc:InvoicedQuantity>31</cbc:InvoicedQuantity>
        <cbc:LineExtensionAmount currencyID="EUR">36</cbc:LineExtensionAmount>
        <cac:InvoicePeriod>
            <cbc:StartDate>2020-01-01</cbc:StartDate>
            <cbc:EndDate>2020-01-31</cbc:EndDate>
        </cac:InvoicePeriod>
        <cac:TaxTotal>
            <cbc:TaxAmount currencyID="EUR">194.05</cbc:TaxAmount>
            <cac:TaxSubtotal>
                <cbc:TaxableAmount currencyID="EUR">924.05</cbc:TaxableAmount>
                <cbc:TaxAmount currencyID="EUR">194.05</cbc:TaxAmount>
                <cac:TaxCategory>
                    <cbc:ID schemeID="UNCL5305">S</cbc:ID>
                    <cbc:Percent>21</cbc:Percent>
                    <cac:TaxScheme>
                        <cbc:ID>VAT</cbc:ID>
                    </cac:TaxScheme>
                </cac:TaxCategory>
            </cac:TaxSubtotal>
        </cac:TaxTotal>
        <cac:Item>
            <cbc:Description>Description</cbc:Description>
            <cac:AdditionalItemProperty>
                <cbc:Name>Channel</cbc:Name>
                <cbc:Value>EMA</cbc:Value>
            </cac:AdditionalItemProperty>
            <cac:AdditionalItemProperty>
                <cbc:Name>ArrivalTime</cbc:Name>
                <cbc:Value></cbc:Value>
            </cac:AdditionalItemProperty>
            <cac:AdditionalItemProperty>
                <cbc:Name>StartGlobalInvoicePeriod</cbc:Name>
                <cbc:Value>StartGlobalInvoicePeriodValue</cbc:Value>
            </cac:AdditionalItemProperty>
            <cac:AdditionalItemProperty>
                <cbc:Name>EndGlobalInvoicePeriod</cbc:Name>
                <cbc:Value>EndGlobalInvoicePeriodValue</cbc:Value>
            </cac:AdditionalItemProperty>
            <cac:AdditionalItemProperty>
                <cbc:Name>Annex</cbc:Name>
                <cbc:Value>AnnexValue</cbc:Value>
            </cac:AdditionalItemProperty>
        </cac:Item>
        <cac:Price>
            <cbc:PriceAmount currencyID="EUR">36</cbc:PriceAmount>
            <cbc:BaseQuantity>1</cbc:BaseQuantity>
        </cac:Price>
    </cac:InvoiceLine>
</Invoice>

In my example generated there is no cec.

I see that your code (UBL21NamespaceContext), you initialise:

  protected UBL21NamespaceContext ()
  {
    addMapping ("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
    addMapping ("xs", XMLConstants.W3C_XML_SCHEMA_NS_URI);
    addMapping ("cac", CUBL21.XML_SCHEMA_CAC_NAMESPACE_URL);
    addMapping ("cbc", CUBL21.XML_SCHEMA_CBC_NAMESPACE_URL);
    addMapping ("cec", CUBL21.XML_SCHEMA_CEC_NAMESPACE_URL);
    addMapping ("ds", CXMLDSig.NAMESPACE_URI);
  }

But cec is not removed when not present.

@phax
Copy link
Owner

phax commented Mar 5, 2020

That is indeed weird. Well the underlying XML "text" is created by JAXB and we only have limited control over it. So if you remove the "cec" mapping, but JAXB creates the "ns2" namespace prefix, I don't know why:

var writer = UBL21Writer.invoice();
MapBasedNamespaceContext context = UBL21NamespaceContext.getInstance().getClone();
context.removeMapping("cec");
writer.setNamespaceContext(context);

var status = writer.write(ublInvoice, file);

Ah you are using Java 10 or newer??? Are you including JAXB 2.3.x in your code?

@patricksan
Copy link
Author

Hi @phax ,

We are using Java 11 ( oracle 11.0.5)
In our classpath we have JAXB 2.3.2

I noticed that you create and already close a bug #17.
Is it automatically deployed to Maven Repository?

@phax
Copy link
Owner

phax commented Mar 6, 2020

#17 is still open. Can you explain to be if UBL.PE still requires UBL 2.0 or whether everything is on UBL 2.1 now? My spanish is a bit poor ;-)

@patricksan
Copy link
Author

Sorry @phax, I meant phax/ph-commons#17.
This one you closed. The open item #17 I have no knowledge about it.

My Spanish is also poor. But I think I could help if you give more details. :-)

@phax
Copy link
Owner

phax commented Mar 6, 2020

Ah okay - no release for that one yet.
That is an edge case that only occurs, if you modify the singleton directly (so don't call "removeMapping" directory on UBL21NamespaceContext.getInstance()) - if you remove only on the "clone" you are fine.

@patricksan
Copy link
Author

Hi @phax, if I use the getClone() as I added in previous message, we get this exception:

Caused by: java.lang.IllegalStateException: Internal inconsistency removing 'cec' and 'urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2'
	at com.helger.xml.namespace.MapBasedNamespaceContext.removeMapping(MapBasedNamespaceContext.java:244)

That is why I asked about the release.

@stale
Copy link

stale bot commented Jun 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 5, 2020
@phax phax added pinned and removed wontfix labels Jun 5, 2020
@phax
Copy link
Owner

phax commented Jul 11, 2020

I am nevertheless closing this issue now. Please re-open, if you see the need for that.

@phax phax closed this as completed Jul 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants