GithubHelp home page GithubHelp logo

UBL 2.0 NameSpace question about ph-ubl HOT 12 CLOSED

phax avatar phax commented on August 15, 2024
UBL 2.0 NameSpace question

from ph-ubl.

Comments (12)

GunterO avatar GunterO commented on August 15, 2024 1

Neither, it was because of the hovering over "aWriter", but I could inspect aWriter via Evaluate Expression. I think it is the IDE which is causing this.
image

from ph-ubl.

GunterO avatar GunterO commented on August 15, 2024 1

I just did, thanks!

from ph-ubl.

GunterO avatar GunterO commented on August 15, 2024

Also, then I don't clone the instance, the ns4 prefix is not there.

_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

Used code:
final ESuccess eSuccess = UBL20Writer.invoice().write(aInvoice, new File(fn));
Why is that?
Thanks!

from ph-ubl.

GunterO avatar GunterO commented on August 15, 2024

I could get rid of the prefix by adding this:
aNsCtx.addDefaultNamespaceURI("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
But the extra namespace/mapping are not added dough.

from ph-ubl.

phax avatar phax commented on August 15, 2024

Hi. So

MapBasedNamespaceContext aNsCtx = UBL20NamespaceContext.getInstance().getClone();
aNsCtx.addMapping("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
aWriter.setNamespaceContext(aNsCtx);
final ESuccess eSuccess = aWriter.write(aInvoice, new File(fn));

would be the correct solution.
What is __prefix:ns4 exactly. Can you paste the XML here?
Is it

prefix="ns4"

or so?

from ph-ubl.

GunterO avatar GunterO commented on August 15, 2024

Thanks for your quick reply!

Correct, that's the code I use. However, when I add this line, the "ns4" prefix is not there:
aNsCtx.addDefaultNamespaceURI("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
This "__prefix:ns4" is something the XML viewer is showing because of the prefix in the XML file.
I can't drop the XML extension here, so I renamed the file to sample.txt.

sample.txt

from ph-ubl.

phax avatar phax commented on August 15, 2024

Ah okay got it - you have a weird XML viewer ;-)
Try this - combining both:

MapBasedNamespaceContext aNsCtx = UBL20NamespaceContext.getInstance().getClone();
aNsCtx.addMapping("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
aNsCtx.addDefaultNamespaceURI("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
aWriter.setNamespaceContext(aNsCtx);
final ESuccess eSuccess = aWriter.write(aInvoice, new File(fn));

from ph-ubl.

GunterO avatar GunterO commented on August 15, 2024

Yes, that's what I tried in the first place, but it is resulting in an XML without the "ns4" prefix, but without the "qdt" namespace line:
sample2.txt

from ph-ubl.

GunterO avatar GunterO commented on August 15, 2024

It is there, but for some reason, it don't gets saved:
image

from ph-ubl.

phax avatar phax commented on August 15, 2024

It says "thew NullPointerException" - is "fn" or "aInvoice" null?

from ph-ubl.

phax avatar phax commented on August 15, 2024

Can you send me a bit more code privately - see the pom.xml for my email address. Thx

from ph-ubl.

GunterO avatar GunterO commented on August 15, 2024

Reason/solution:
In general, the underlying JAXB only writes the XML namespaces it (whysoever) needs.
And as the qdt namespace ( "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2") is not used, it is not emitted.
If you would use an element that would require this namespace, than it would be there.

from ph-ubl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.