no prefix in document
jpaezlancheros opened this issue · comments
Hello Phax
I want to ask you , how is it possible to have the document without the prefix, I mean
<Invoice xmlns=.... instead of <ns6:Invoice xmlns:ns6-........
Thank you
It is possible.
How do you currently write your invoices to a file?
Are you using something like UBL21Writer
or similiar?
You should look for "NamespaceContext" to use...
hi thanks for your response... well I was trying with ubl22writer.. before tax agency in Colombia was asking for spwcific namespace but now they removed it...
what I see is that writer sets a defsult namespace
With the UBL22Writer you can do as follows:
final MapBasedNamespaceContext aNSContext = UBL22NamespaceContext.getInstance ().getClone ();
aNSContext.addDefaultNamespaceURI ("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
aNSContext.addMapping ("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
writer.setNamespaceContext (aNSContext);
You should get the picture.....
Hello
Well I tried but still getting the prefix in root element "<ns6:Invoice" .
Thanks
Can you please provide me with some code sample?
Find my email address in the pom.xml file...
Hello
You are right as your answer it works. Than You Very Much.
Hola jpaezlancheros . Como resolviste el asunto con los prefijos de la DIAN. "sts".
@MauHenGH please ask in English - I don't understand spanish :(
Sorry, i tried to ask @jpaezlancheros directly. I need to add a new namespace on the invoice document, but is'nt from UBL.
aCtx.addMapping ("sts", "dian:gov:co:facturaelectronica:Structures-2-1");
It's a structure (UBLExtension) asked from the tax Agency in Colombia. I need to adding this namespace on the root (invoice). aCtx.addMapping its no working.
final MapBasedNamespaceContext aNSContext = UBL22NamespaceContext.getInstance ().getClone ();
aNSContext.addDefaultNamespaceURI ("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
aNSContext.addMapping ("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
aNSContext.addMapping ("sts", "dian:gov:co:facturaelectronica:Structures-2-1");
writer.setNamespaceContext (aNSContext);
should do the trick (for UBL 2.2)
It's important to add the mapping before calling setNamespaceContext
Hello MauHenGH
I created a custom Namespace context (instead of UBL22NamespaceContext but same structure) for name spaces of dian where I added all of them.
UBLCO21NamespaceContext() {
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 ("ext", CUBL21.XML_SCHEMA_CEC_NAMESPACE_URL);
addMapping ("csc", CUBL21.XML_SCHEMA_CSC_NAMESPACE_URL);
addMapping("sts","dian:gov:co:facturaelectronica:Structures-2-1");
}
then I call
final MapBasedNamespaceContext aNSContext = UBLCO21NamespaceContext.getInstance ().getClone (); as Phillip notes.
and It worked well.
Thank's @jpaezlancheros . It still not working for me. I have this result.
Wich library did you use to build the sts:DianExtension.?
You are eventually missing the call to 'addDefaultMapping'?? It maps the '' (empty string) prefix...
addDefaultMapping
addDefaultNamespaceURI?
Mau
to have <Invoice instead of <ns4:Invoice I did this as Phillip note,
final MapBasedNamespaceContext aNsCtx = UBLCO21NamespaceContext.getInstance().getClone();
aNsCtx.addDefaultNamespaceURI("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
aBuilder.setNamespaceContext(aNsCtx);
and to build the Dian extension it was easier for me created custom UBL agregate components(and subcomponents, ) i.e. I had to create this elements
"DianExtensionsType"
"invoiceControl",
"invoiceSource",
"softwareProvider",
"softwareSecurityCode",
"authorizationProvider",
"qrCode",
"legalMonetaryTotal"
in same way as ubl elements , so for example Dian extension is built this way:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DianExtensionsType", propOrder = {
"invoiceControl",
"invoiceSource",
"softwareProvider",
"softwareSecurityCode",
"authorizationProvider",
"qrCode",
"legalMonetaryTotal"
})
@CodingStyleguideUnaware
public class DianExtensionsType implements Serializable, IExplicitlyCloneable {
@XmlElement(name = "SoftwareProvider", namespace = CUBLCO21.XML_SCHEMA_STS_NAMESPACE_URL)
private SoftwareProviderType softwareProvider;
@XmlElement(name = "SoftwareSecurityCode", namespace = CUBLCO21.XML_SCHEMA_STS_NAMESPACE_URL)
private IdentifierType softwareSecurityCode;
@XmlElement(name = "InvoiceSource", namespace = CUBLCO21.XML_SCHEMA_STS_NAMESPACE_URL)
private CountryType invoiceSource;
@XmlElement(name = "InvoiceControl", namespace = CUBLCO21.XML_SCHEMA_STS_NAMESPACE_URL)
private InvoiceControlType invoiceControl;
@XmlElement(name = "AuthorizationProvider", namespace = CUBLCO21.XML_SCHEMA_STS_NAMESPACE_URL)
private AuthorizationProviderType authorizationProvider;
@XmlElement(name = "QRCode", namespace = CUBLCO21.XML_SCHEMA_STS_NAMESPACE_URL)
private QrCodeType qrCode;
@XmlElement(name = "LegalMonetaryTotal", namespace = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2", required = true)
private MonetaryTotalType legalMonetaryTotal;
public DianExtensionsType() {
}
@Nullable
public SoftwareProviderType getSoftwareProvider() {
return softwareProvider;
}
public void setSoftwareProvider(
@Nullable SoftwareProviderType value) {
this.softwareProvider = value;
}
@Nullable
public IdentifierType getSoftwareSecurityCode() {
return softwareSecurityCode;
}
public void setSoftwareSecurityCode(
@Nullable IdentifierType value) {
this.softwareSecurityCode = value;
}
@Nullable
public CountryType geInvoiceSource() {
return invoiceSource;
}
public void setInvoiceSource(
@Nullable CountryType value) {
this.invoiceSource = value;
}
@Nullable
public InvoiceControlType getInvoiceControl() {
return invoiceControl;
}
public void setInvoiceControl(
@Nullable InvoiceControlType value) {
this.invoiceControl = value;
}
@Nullable
public AuthorizationProviderType getAuthorizationProvider() {
return authorizationProvider;
}
public void setAuthorizationProvider(
@Nullable AuthorizationProviderType value) {
this.authorizationProvider = value;
}
@Nullable
public QrCodeType getQrCode() {
return qrCode;
}
public void setQrCode(
@Nullable QrCodeType value) {
this.qrCode = value;
}
@Nullable
public MonetaryTotalType getLegalMonetaryTotal() {
return legalMonetaryTotal;
}
/**
* Sets the value of the legalMonetaryTotal property.
*
* @param value
* allowed object is
* {@link MonetaryTotalType }
*
*/
public void setLegalMonetaryTotal(
@Nullable
MonetaryTotalType value) {
this.legalMonetaryTotal = value;
}
public void cloneTo(
@Nonnull DianExtensionsType ret) {
ret.softwareProvider = ((softwareProvider == null) ? null : softwareProvider.clone());
ret.softwareSecurityCode = ((softwareSecurityCode == null) ? null : softwareSecurityCode.clone());
ret.invoiceControl = ((invoiceControl == null) ? null : invoiceControl.clone());
ret.invoiceSource = ((invoiceSource == null) ? null : invoiceSource.clone());
ret.authorizationProvider = ((authorizationProvider == null) ? null : authorizationProvider.clone());
ret.qrCode = ((qrCode == null) ? null : qrCode.clone());
ret.legalMonetaryTotal = ((legalMonetaryTotal == null)?null:legalMonetaryTotal.clone());
}
@Nonnull
@ReturnsMutableCopy
@Override
public DianExtensionsType clone() {
DianExtensionsType ret = new DianExtensionsType();
cloneTo(ret);
return ret;
}
}
Hi @phax .
Im trying to add to the ExtensionContent an object from an xsd. This one belongs to another namespace. I need (picture) import this to Invoice element.
How can i do that?
Hi. It is not important where this namespace is defined. The semantics of the XML are equivalent no matter where it is defined.
And as the serialization is handled by Jaxb, and there is no configuration option for that in Jaxb you need to live with it - sorry.
Why do you "need" the namespace prefix in the root element?
The Validation system of the tax Agency it's rejecting me the document.
"Namespace prefix 'sts' is not defined"
Can you send me the full document via email please? See pom.xml for my email address.
@jpaezlancheros Have you the same issue?
I had no such validation error. My xml looks like
<Invoice xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:xades="http://uri.etsi.org/01903/v1.3.2#"
xmlns:sts="dian:gov:co:facturaelectronica:Structures-2-1"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionContent>
<sts:DianExtensions xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:sts="dian:gov:co:facturaelectronica:Structures-2-1">
<sts:InvoiceControl>
<sts:InvoiceAuthorization>18760000001</sts:InvoiceAuthorization>
<sts:AuthorizationPeriod>
<cbc:StartDate>2019-01-19</cbc:StartDate>
<cbc:EndDate>2030-01-19</cbc:EndDate>
</sts:AuthorizationPeriod>
<sts:AuthorizedInvoices>
<sts:Prefix>SETT</sts:Prefix>
with no problem,
Can one of you guys send me the link to "kit facturacion electronica validacion previa" - I can't find :(
it is no so clear , I remember a had som issues with xsd validator included in toolkit regarding namespaces. the only changed namespace from standard was sts:"dian:gov:co:facturaelectronica:Structures-2-1" . So I fixed using custom UBLCO21NamespaceContext() { ...
SInce I add direct support for Peru or Turkey UBL subset, I can add one for Colombia as well... :)
@jpaezlancheros Can i get in touch with you via email?.
thks Phillip
ok to have the UBL subset for colombia . I just generate a version of UBLCO21.java
EUBL21DocumentType.java
UBLCO21DocumentTypes.java
UBLCO21NamespaceContext.java
UBLCO21Reader.java
UBLCO21ReaderBuilder.java
UBLCO21Validator.java
UBLCO21ValidatorBuilder.java
UBLCO21Writer.java
UBLCO21WriterBuilder.java
for colombia , and in order to add in the UBLExtensions, the custom extension required from our tax agency i had to modify the ,"ExtensionContentType" to allow adding such custom extension because set Any does not allow to add it.\Jorge
So "UBLCO" is a better name than "DianUBL"?
think its better DianUBL, I used first UBLCO...at once
.
Than please have a look at https://github.com/phax/ph-ubl/tree/master/ph-ubl-dian/src/main/java/com/helger/dianubl
Can you create a PR for necessary changes?