Programa en Java para convertir xml de UBL 2.0 a UBL 2.1 en MICROS 9700 HMS

Los archivos XML correspondientes a la versión UBL 2.0 del MICROS 9700 HMS se encuentran en la siguiente ubicación del Workstation “C:\Program Files\Micros\eJournal 15.2.1.6\Data\PE\Backup\Docs”. Con este programa en java se realiza la conversión del XML UBL 2.0 al correspondiente XML UBL 2.1.

 

UBL (Universal Business Language) es una librería estándar de documentos XML, diseñados para representar documentos empresariales tales como órdenes de venta o facturas. Ha sido desarrollada por un comité técnico de la organización OASIS, con la participación de varias organizaciones relacionadas con los estándares de datos en la industria. UBL está pensada para integrarse directamente en las prácticas empresariales, legales, auditoras o de gestión de registros actualmente vigentes.

UBL es propiedad de OASIS y actualmente está disponible para todos, sin tarifas de regalías. La biblioteca de documentos empresariales de la UBL es un lenguaje de marcado bien desarrollado con validadores, software de creación, analizadores y generadores. [3] La versión 2.0 de UBL se aprobó como norma OASIS en octubre de 2006. La versión 2.1 se aprobó como norma OASIS en noviembre de 2013 y como norma ISO (ISO / IEC 19845: 2015) en diciembre de 2015. La versión 2.2 se aprobó como OASIS Estándar en julio de 2018. La versión 2.1 es totalmente compatible con la versión 2.0, pero agrega 34 nuevos esquemas de documentos, lo que eleva el total de los tipos de documentos comerciales definidos por UBL a 65. La versión 2.2 es totalmente compatible con la versión 2.1, y agrega otra 16 tipos de documentos para un total de 81.

package com.org.ws;

 

import java.io.File;

 

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

 

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NamedNodeMap;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

 

/**

 * Conversion del xml ubl 2.0 a xml ubl 2.1 para micros 9700 HMS

 * @author master

 */

public class ConvertUBL20toUBL21Final {

 

       public static final String xmlFilePath_ubl20 = “D:\\test\\factura_micros_20.xml”;

      

       public static final String xmlFilePath_ubl21 = “D:\\test\\factura_micros9700_21_result.xml”;

        

    public static void main(String argv[]) {

       ConvertUBL20toUBL21Final t =new ConvertUBL20toUBL21Final();

       t.convert();

    }

      

    public void convert(){

       try {

            File xmlFile = new File(xmlFilePath_ubl20);

 

            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

 

            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

 

            Document doc = documentBuilder.parse(xmlFile);

 

            doc.getDocumentElement().normalize();

 

            System.out.println(“Root element :” + doc.getDocumentElement().getNodeName());

 

            NodeList nodeList = doc.getElementsByTagName(“sac:AdditionalInformation”);

           

            System.out.println(“===============================================================”);

           

            

            /*

             * create node

            <sac:AdditionalMonetaryTotal>

            <cbc:ID>2005</cbc:ID>

            <cbc:PayableAmount currencyID=”PEN”>0.0</cbc:PayableAmount>

            </sac:AdditionalMonetaryTotal>

            */

            Node additionalInformation = doc.getElementsByTagName(“sac:AdditionalInformation”).item(0);

           

                   Element addNode = doc.createElement(“sac:AdditionalMonetaryTotal”);

                   additionalInformation.appendChild(addNode);

                         Element cbcID = doc.createElement(“cbc:ID”);

                         cbcID.appendChild(doc.createTextNode(“2005”));

                         addNode.appendChild(cbcID);

                        

                         Element cbcPayableAmount = doc.createElement(“cbc:PayableAmount”);

                         cbcPayableAmount.setAttributeNS(null, “currencyID”, “PEN”);

                         cbcPayableAmount.setIdAttributeNS(null, “currencyID”, true);

                        

                         cbcPayableAmount.appendChild(doc.createTextNode(“0.0”));

                                NamedNodeMap attribute = cbcPayableAmount.getAttributes();

                                Node nodeAttr = attribute.getNamedItem(currencyID”);

                               

                                nodeAttr.setTextContent(“PEN”);

                         addNode.appendChild(cbcPayableAmount);

           

                 /*

                  * change value

                 <cbc:UBLVersionID>2.1</cbc:UBLVersionID>      

                 */

                 Node UBLVersionID = doc.getElementsByTagName(“cbc:UBLVersionID”).item(0);

                 UBLVersionID.setTextContent(2.1″);        

                

                 /*

                  * change value

                  * add attribute schemeAgencyName

                 <cbc:CustomizationID schemeAgencyName=”PE:SUNAT”>2.0</cbc:CustomizationID>

                 */

                 Node CustomizationID = doc.getElementsByTagName(“cbc:CustomizationID”).item(0);

                 CustomizationID.setTextContent(“2.0”);

                

                 ((Element)CustomizationID).setAttribute(schemeAgencyName”, “PE:SUNAT”);

           

                 /*

                  * create node into Invoice

                 <cbc:IssueTime>14:56:12.0Z</cbc:IssueTime>

                 */

                 Node Invoice = doc.getElementsByTagName(Invoice”).item(0);

           

            Element IssueTime = doc.createElement(“cbc:IssueTime”);

            IssueTime.appendChild(doc.createTextNode(“16:00:00.0Z”));

            Invoice.appendChild(IssueTime);

           

            /*

             * add attribute

             * <cbc:InvoiceTypeCode listID=”0101″ listAgencyName=”PE:SUNAT” listName=”Tipo de Documento” name=”Tipo de Operacion” listURI=”urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01″ listSchemeURI=”urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo51″>01</cbc:InvoiceTypeCode>

             */

            Node InvoiceTypeCode = doc.getElementsByTagName(“cbc:InvoiceTypeCode”).item(0);

                 ((Element)InvoiceTypeCode).setAttribute(“listID”, “0101”);

                 ((Element)InvoiceTypeCode).setAttribute(“listAgencyName”, “PE:SUNAT”);

                 ((Element)InvoiceTypeCode).setAttribute(“listName”, “Tipo de Documento”);

                 ((Element)InvoiceTypeCode).setAttribute(“name”, “Tipo de Operacion”);

                 ((Element)InvoiceTypeCode).setAttribute(“listURI”, “urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01″);

                 ((Element)InvoiceTypeCode).setAttribute(“listSchemeURI”, “urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo51″);

                

                 /*

                  * add attribute

                  * <cbc:DocumentCurrencyCode listID=”ISO 4217 Alpha” listAgencyName=”United Nations Economic Commission for Europe” listName=”Currency”>PEN</cbc:DocumentCurrencyCode>

                  */

                 Node DocumentCurrencyCode = doc.getElementsByTagName(“cbc:DocumentCurrencyCode”).item(0);

                 ((Element)DocumentCurrencyCode).setAttribute(“listID”, “ISO 4217 Alpha”);

                 ((Element)DocumentCurrencyCode).setAttribute(listAgencyName”, “United Nations Economic Commission for Europe”);

                 ((Element)DocumentCurrencyCode).setAttribute(“listName”, “Currency”);

                

               Node AccountingSupplierParty = doc.getElementsByTagName(“cac:AccountingSupplierParty”).item(0);

            NodeList nodeNodesSupplier = AccountingSupplierParty.getChildNodes();

            if (nodeNodesSupplier != null) {

            for(int i=0;i<nodeNodesSupplier.getLength();i++){

                    Node childNode = nodeNodesSupplier.item(i);

                    if(childNode.getNodeName().equals(“cac:Party”)){

                          Element PartyIdentification = doc.createElement(“cac:PartyIdentification”);

                          childNode.appendChild(PartyIdentification);

                        Element cbcIDpi = doc.createElement(“cbc:ID”);

                        cbcIDpi.appendChild(doc.createTextNode(“0000000000”));//RUC PROVEEDOR

                        PartyIdentification.appendChild(cbcIDpi);

                        

                        cbcIDpi.setAttribute(“schemeID”, “6”);

                        cbcIDpi.setAttribute(“schemeName”, “Documento de Identidad”);

                        cbcIDpi.setAttribute(schemeAgencyName”, “PE:SUNAT”);

                        cbcIDpi.setAttribute(“schemeURI”, “urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06″);

                    

                    NodeList nodeNodesParty=childNode.getChildNodes();

                    if (nodeNodesParty != null) {

                          for(int j=0;j<nodeNodesParty.getLength();j++){

                                 Node childNodeParty = nodeNodesParty.item(j);

                                 if(childNodeParty.getNodeName().equals(“cac:PostalAddress”)){

                                       //<cbc:CitySubdivisionName>DEFAULT PARAMETER</cbc:CitySubdivisionName>

                                       Element CitySubdivisionName = doc.createElement(“cbc:CitySubdivisionName”);

                                        CitySubdivisionName.appendChild(doc.createTextNode(“DEFAULT PARAMETER”));

                                       childNodeParty.appendChild(CitySubdivisionName);

                                      

                                       //<cbc:CountrySubentity>SAN ISIDRO – LIMA</cbc:CountrySubentity>

                                       Element CountrySubentity = doc.createElement(“cbc:CountrySubentity”);

                                       CountrySubentity.appendChild(doc.createTextNode(“SAN ISIDRO – LIMA”));

                                       childNodeParty.appendChild(CountrySubentity);

                                      

                                       //<cbc:District>DEFAULT PARAMETER</cbc:District>

                                       Element District = doc.createElement(“cbc:District”);

                                       District.appendChild(doc.createTextNode(“DEFAULT PARAMETER”));

                                       childNodeParty.appendChild(District);

                                 }

                                

                                

                                 if(childNodeParty.getNodeName().equals(“cac:PartyLegalEntity”)){

                                       //<cac:RegistrationAddress>

                                       Element RegistrationAddress = doc.createElement(“cac:RegistrationAddress”);

                                       childNodeParty.appendChild(RegistrationAddress);

                                      

                                              //<cbc:AddressTypeCode listAgencyName=”PE:SUNAT” listName=”Establecimientos anexos“>0000</cbc:AddressTypeCode>

                                              Element AddressTypeCode = doc.createElement(“cbc:AddressTypeCode”);

                                               AddressTypeCode.appendChild(doc.createTextNode(“0000”));

                                              RegistrationAddress.appendChild(AddressTypeCode);

                                                     AddressTypeCode.setAttribute(listAgencyName”, “PE:SUNAT”);

                                                     AddressTypeCode.setAttribute(“listName”, “Establecimientos anexos”);

                                       

                                              //<cbc:CitySubdivisionName>DEFAULT PARAMETER</cbc:CitySubdivisionName>

                                              Element CitySubdivisionName = doc.createElement(“cbc:CitySubdivisionName”);

                                               CitySubdivisionName.appendChild(doc.createTextNode(“DEFAULT PARAMETER”));

                                               RegistrationAddress.appendChild(CitySubdivisionName);

                                             

                                              //<cbc:CityName>SAN ISIDRO – LIMA</cbc:CityName>

                                              Element CityName = doc.createElement(“cbc:CityName”);

                                              CityName.appendChild(doc.createTextNode(“SAN ISIDRO – LIMA”));

                                              RegistrationAddress.appendChild(CityName);

                                             

                                              //<cbc:CountrySubentity>SAN ISIDRO – LIMA</cbc:CountrySubentity>

                                              Element CountrySubentity = doc.createElement(“cbc:CountrySubentity”);

                                               CountrySubentity.appendChild(doc.createTextNode(“SAN ISIDRO – LIMA”));

                                              RegistrationAddress.appendChild(CountrySubentity);

                                      

                                              //<cbc:CountrySubentityCode listAgencyName=”PE:INEI” listName=”Ubigeos“>150131</cbc:CountrySubentityCode>

                                              Element CountrySubentityCode = doc.createElement(“cbc:CountrySubentityCode”);

                                               CountrySubentityCode.appendChild(doc.createTextNode(“150131”));

                                               RegistrationAddress.appendChild(CountrySubentityCode);

                                                     AddressTypeCode.setAttribute(listAgencyName”, “PE:INEI”);

                                                     AddressTypeCode.setAttribute(listName”, “Ubigeos”);

                                             

                                              //<cbc:District>DEFAULT PARAMETER</cbc:District>

                                              Element District = doc.createElement(“cbc:District”);

                                              District.appendChild(doc.createTextNode(“DEFAULT PARAMETER”));

                                              RegistrationAddress.appendChild(District);

                                             

                                              /*

                                              <cac:AddressLine>

                                              <cbc:Line>CALLE NNN SAN ISIDRO – LIMA</cbc:Line>

                                              </cac:AddressLine>

                                              */

                                              Element AddressLine = doc.createElement(“cac:AddressLine”);

                                              RegistrationAddress.appendChild(AddressLine);

                                                     Element Line = doc.createElement(“cbc:Line”);

                                                    Line.appendChild(doc.createTextNode(“CALLE NNN SAN ISIDRO – LIMA”));

                                                    AddressLine.appendChild(Line);

                                             

                                              /*

                                              <cac:Country>

                                                           <cbc:IdentificationCode listID=”ISO 3166-1″ listAgencyName=”United Nations Economic Commission for Europe” listName=”Country”>PE</cbc:IdentificationCode>

                                                        </cac:Country>

                                              */

                                              Element Country = doc.createElement(“cac:Country”);

                                              RegistrationAddress.appendChild(Country);

                                                    Element IdentificationCode = doc.createElement(“cbc:IdentificationCode”);

                                                     IdentificationCode.appendChild(doc.createTextNode(“PE”));

                                                    Country.appendChild(IdentificationCode);

                                                            IdentificationCode.setAttribute(“listID”, “ISO 3166-1”);

                                                            IdentificationCode.setAttribute(“listAgencyName”, “United Nations Economic Commission for Europe”);

                                                            IdentificationCode.setAttribute(“listName”, “Country”);

                                                          

                                 }

                                

                                

                          }

                    }

                        

                    }

            }

            }

                   

           

            Node AccountingCustomerParty = doc.getElementsByTagName(“cac:AccountingCustomerParty”).item(0);

            NodeList nodeNodesCustomer = AccountingCustomerParty.getChildNodes();

            if (nodeNodesCustomer != null) {

            for(int i=0;i<nodeNodesCustomer.getLength();i++){

                    Node childNode = nodeNodesCustomer.item(i);

                    if(childNode.getNodeName().equals(“cac:Party”)){

                          /*

                          * <cac:PartyIdentification>

                                 <cbc:ID schemeID=”6″ schemeName=”Documento de Identidad” schemeAgencyName=”PE:SUNAT” schemeURI=”urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06″>20559622193</cbc:ID>

                                        </cac:PartyIdentification>

                          */

                          Element PartyIdentification = doc.createElement(“cac:PartyIdentification”);

                          childNode.appendChild(PartyIdentification);

                        Element cbcIDpi = doc.createElement(“cbc:ID”);

                        cbcIDpi.appendChild(doc.createTextNode(“9999999999”));//RUC CLIENTE

                        PartyIdentification.appendChild(cbcIDpi);

                        cbcIDpi.setAttribute(“schemeID”, “6”);

                        cbcIDpi.setAttribute(“schemeName”, “Documento de Identidad”);

                        cbcIDpi.setAttribute(schemeAgencyName”, “PE:SUNAT”);

                         cbcIDpi.setAttribute(“schemeURI”, “urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06″);

                    

                    /*

                    *<cac:PartyName>

                                       <cbc:Name>MAXIMA SEGURIDAD ATENAS SAC</cbc:Name>

                                    </cac:PartyName>

                    */

                         Element PartyName = doc.createElement(“cac:PartyName”);

                          childNode.appendChild(PartyName);

                         Element Name = doc.createElement(“cbc:Name”);

                        Name.appendChild(doc.createTextNode(“CLIENTE S.A.”));//RAZON SOCIAL CLIENTE

                        PartyName.appendChild(Name);

                    

                        

                    NodeList nodeNodesParty = childNode.getChildNodes();   

                    if (nodeNodesParty != null) {

                          for(int j=0;j<nodeNodesParty.getLength();j++){

                                 Node childNodeParty = nodeNodesParty.item(j);

                                 if(childNodeParty.getNodeName().equals(“cac:PartyLegalEntity”)){

                                      

                                       Element RegistrationAddress = doc.createElement(“cac:RegistrationAddress”);

                                       childNodeParty.appendChild(RegistrationAddress);

                                      

                                              //<cbc:CityName>AREQUIPA</cbc:CityName>

                                              Element CityName = doc.createElement(“cbc:CityName”);

                                               CityName.appendChild(doc.createTextNode(“AREQUIPA”));

                                              RegistrationAddress.appendChild(CityName);

                                             

                                              /*<cac:AddressLine>

                                           *<cbc:Line>CALLE NNN – AREQUIPA</cbc:Line>

                                           *</cac:AddressLine>

                                           */

                                              Element AddressLine = doc.createElement(“cac:AddressLine”);

                                              RegistrationAddress.appendChild(AddressLine);

                                                    Element Line = doc.createElement(“cbc:Line”);

                                                    Line.appendChild(doc.createTextNode(“CALLE NNN – AREQUIPA”));

                                                    AddressLine.appendChild(Line);

                                 }

                          }

                    }

                    

                    }

            }

            }

           

            NodeList nodesInvoice = Invoice.getChildNodes();

            if (nodesInvoice != null) {

            for(int i=0;i<nodesInvoice.getLength();i++){

                    Node childNode = nodesInvoice.item(i);

                    if(childNode.getNodeName().equals(“cac:TaxTotal”)){

                         

                        NodeList nodesTaxTotal = childNode.getChildNodes();

                        if (nodesTaxTotal != null) {

                          for(int m=0;m<nodesTaxTotal.getLength();m++){

                                 Node childNodeTaxTotal = nodesTaxTotal.item(m);

                                 if(childNodeTaxTotal.getNodeName().equals(“cac:TaxSubtotal”)){

                         

                                                     //<cbc:TaxableAmount currencyID=”PEN”>150.79</cbc:TaxableAmount>

                                                     Element TaxableAmount = doc.createElement(“cbc:TaxableAmount”);

                                                      TaxableAmount.appendChild(doc.createTextNode(“150.79”));

                                                     childNodeTaxTotal.appendChild(TaxableAmount);

                                                     TaxableAmount.setAttribute(currencyID”, “PEN”);

                                                    

                                                             NodeList nodesTaxSubTotal = childNodeTaxTotal.getChildNodes();

                                                    if (nodesTaxSubTotal != null) {

                                                     for(int j=0;j<nodesTaxSubTotal.getLength();j++){

                                                            Node childTaxTotal = nodesTaxSubTotal.item(j);

                                                            if(childTaxTotal.getNodeName().equals(“cac:TaxCategory”)){

                                                                 

                                                                  NodeList nodesTaxCategory = childTaxTotal.getChildNodes();

                                                                 if (nodesTaxCategory != null) {

                                                                  for(int k=0;k<nodesTaxCategory.getLength();k++){

                                                                         Node childTaxCategory = nodesTaxCategory.item(k);

                                                                         if(childTaxCategory.getNodeName().equals(“cac:TaxScheme”)){

                                                                               //<cbc:ID schemeAgencyName=”PE:SUNAT” schemeName=”Codigo de tributos” schemeURI=”urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo05″>1000</cbc:ID>

                                                                              

                                                                               NodeList nodesTaxSchema = childTaxCategory.getChildNodes();

                                                                                     if (nodesTaxSchema != null) {

                                                                                      for(int x=0;x<nodesTaxSchema.getLength();x++){

                                                                                             Node childTaxScheme = nodesTaxSchema.item(x);

                                                                                             if(childTaxScheme.getNodeName().equals(“cbc:ID”)){

                                                                                                    ((Element)childTaxScheme).setAttribute(schemeAgencyName”, “PE:SUNAT”);

                                                                                                    ((Element)childTaxScheme).setAttribute(“schemeName”, “Codigo de tributos”);

                                                                                                    ((Element)childTaxScheme).setAttribute(“schemeURI”, “urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo05″);

                                                                                             }

                                                                                      }

                                                                                     }

                                                                         }

                                                                  }

                                                                 }

                                                                 

                                                            }

                                                     }

                                                    }

                         

                                        }

                                }

                                }

                    }

                   

                    if(childNode.getNodeName().equals(“cac:LegalMonetaryTotal”)){

                          //<cbc:LineExtensionAmount currencyID=”PEN”>150.79</cbc:LineExtensionAmount>

                          Element LineExtensionAmount = doc.createElement(“cbc:LineExtensionAmount”);

                          LineExtensionAmount.appendChild(doc.createTextNode(“150.79”));

                          childNode.appendChild(LineExtensionAmount);

                          LineExtensionAmount.setAttribute(“currencyID”, “PEN”);

                    }

                   

            }

            }

           

            //Invoce Lines

            NodeList listInvoiceLine = doc.getElementsByTagName(“cac:InvoiceLine”);

            if (listInvoiceLine != null) {

           

            for(int t=0;t<listInvoiceLine.getLength();t++){

                    Node nodeInvoiceLine = listInvoiceLine.item(t);

                   

                    NodeList nodesInvoiceLine = nodeInvoiceLine.getChildNodes();

                    if (nodesInvoiceLine != null) {

                          for(int i=0;i<nodesInvoiceLine.getLength();i++){

                           Node node = nodesInvoiceLine.item(i);

                           if(node.getNodeName().equals(cac:PricingReference”)){

                                

                                 NodeList nodesPricingReference = node.getChildNodes();

                                if (nodesPricingReference != null) {

                                 for(int k=0;k<nodesPricingReference.getLength();k++){

                                       

                                        Node nodePricingReference = nodesPricingReference.item(k);

                                        if(nodePricingReference.getNodeName().equals(“cac:AlternativeConditionPrice”)){

                                             

                                              NodeList nodesAlternativeConditionPrice = nodePricingReference.getChildNodes();

                                             if (nodesAlternativeConditionPrice != null) {

                                              for(int m=0;m<nodesAlternativeConditionPrice.getLength();m++){

                                                     Node nodeAlternativeConditionPrice = nodesAlternativeConditionPrice.item(m);

                                                     if(nodeAlternativeConditionPrice.getNodeName().equals(“cbc:PriceTypeCode”)){

                                                           //<cbc:PriceTypeCode listAgencyName=”PE:SUNAT” listName=”Tipo de Precio” listURI=”urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16″>01</cbc:PriceTypeCode>

                                                          

                                                            ((Element)nodeAlternativeConditionPrice).setAttribute(listAgencyName”, “PE:SUNAT”);

                                                            ((Element)nodeAlternativeConditionPrice).setAttribute(listName”, “Tipo de Precio”);

                                                            ((Element)nodeAlternativeConditionPrice).setAttribute(listURI”, “urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16″);

                                                          

                                                     }

                                              }

                                             }

                                             

                                        }

                                 }

                                }

                           }

                          

                           if(node.getNodeName().equals(cac:TaxTotal”)){

                                

                                 NodeList nodesTaxTotal = node.getChildNodes();

                                if (nodesTaxTotal != null) {

                                 for(int k=0;k<nodesTaxTotal.getLength();k++){

                                       

                                        Node nodeTaxTotal = nodesTaxTotal.item(k);

                                        if(nodeTaxTotal.getNodeName().equals(“cac:TaxSubtotal”)){

                                             

                                              //<cbc:TaxableAmount currencyID=”PEN”>15.63</cbc:TaxableAmount>  

                                              Element TaxableAmount = doc.createElement(“cbc:TaxableAmount”);

                                               TaxableAmount.appendChild(doc.createTextNode(“15.63”));

                                              nodeTaxTotal.appendChild(TaxableAmount);

                                              TaxableAmount.setAttribute(currencyID”, “PEN”);

                                             

                                              NodeList nodesTaxSubtotal = nodeTaxTotal.getChildNodes();

                                             if (nodesTaxSubtotal != null) {

                                              for(int m=0;m<nodesTaxSubtotal.getLength();m++){

                                                    

                                                     Node nodeTaxSubtotal = nodesTaxSubtotal.item(m);

                                                     if(nodeTaxSubtotal.getNodeName().equals(“cac:TaxCategory”)){

                                                          

                                                           //<cbc:Percent>18.0</cbc:Percent>

                                                           Element Percent = doc.createElement(“cbc:Percent”);

                                                            Percent.appendChild(doc.createTextNode(“18.00”));

                                                           nodeTaxSubtotal.appendChild(Percent);

                                                          

                                                           NodeList nodesTaxCategory = nodeTaxSubtotal.getChildNodes();

                                                          if (nodesTaxCategory != null) {

                                                           for(int z=0;z<nodesTaxCategory.getLength();z++){

                                                                 

                                                                  Node nodeTaxCategory = nodesTaxCategory.item(z);

                                                                  if(nodeTaxCategory.getNodeName().equals(“cbc:TaxExemptionReasonCode”)){

                                                                         //<cbc:TaxExemptionReasonCode listAgencyName=”PE:SUNAT” listName=”Afectacion del IGV” listURI=”urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07″>10</cbc:TaxExemptionReasonCode>

                                                                         ((Element)nodeTaxCategory).setAttribute(“listAgencyName”, “PE:SUNAT”);

                                                                         ((Element)nodeTaxCategory).setAttribute(“listName”, “Afectacion del IGV”);

                                                                         ((Element)nodeTaxCategory).setAttribute(“listURI”, “urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07″);

                                                                  }

                                                                 

                                                                  if(nodeTaxCategory.getNodeName().equals(“cac:TaxScheme”)){

                                                                       

                                                                        NodeList nodesTaxSchema = nodeTaxCategory.getChildNodes();

                                                                       if (nodesTaxSchema != null) {

                                                                        for(int p=0;p<nodesTaxSchema.getLength();p++){

                                                                              

                                                                               Node nodeTaxSchema = nodesTaxSchema.item(p);

                                                                               if(nodeTaxSchema.getNodeName().equals(“cbc:ID”)){

                                                                                     //<cbc:ID schemeAgencyName=”PE:SUNAT” schemeName=”Codigo de tributos” schemeURI=”urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo05″>1000</cbc:ID>

                                                                                      ((Element)nodeTaxSchema).setAttribute(schemeAgencyName”, “PE:SUNAT”);

                                                                                      ((Element)nodeTaxSchema).setAttribute(“schemeName”, “Codigo de tributos”);

                                                                                      ((Element)nodeTaxSchema).setAttribute(“schemeURI”, “urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo05″);

                                                                               }

                                                                        }

                                                                       }

                                                                       

                                                                       

                                                                  }

                                                                 

                                                           }

                                                          }

                                                          

                                                           

                                                     }

                                                    

                                              }

                                             }

                                             

                                        }

                                 }

                                }

                           }

      

                           if(node.getNodeName().equals(cac:Item”)){

                                 /*

                                  * <cac:CommodityClassification>

                                  *     <cbc:ItemClassificationCode listID=”UNSPSC” listAgencyName=”GS1 US” listName=”Item Classification”>90101501</cbc:ItemClassificationCode>

                                         * </cac:CommodityClassification>

                                  */

                                 Element CommodityClassification = doc.createElement(“cac:CommodityClassification”);

                                node.appendChild(CommodityClassification);

                                       Element ItemClassificationCode = doc.createElement(“cbc:ItemClassificationCode”);

                                       ItemClassificationCode.appendChild(doc.createTextNode(“90101501”));//CODIGO DE PRODUCTO – 90101501-RESTAURANTES

                                       //90-SERVICIOS DE VIAJES, ALIMENTACIÓN, ALOJAMIENTO Y ENTRETENIMIENTO

                                       //9010-RESTAURANTES Y CATERING (SERVICIOS DE COMIDAS Y BEBIDAS)

                                       //901015-ESTABLECIMIENTOS PARA COMER Y BEBER

                                       CommodityClassification.appendChild(ItemClassificationCode);

                                       

                                       ItemClassificationCode.setAttribute(“listID”, “UNSPSC”);//UNSPSC – Clasificador de Bienes y Servicios

                                       ItemClassificationCode.setAttribute(listAgencyName”, “GS1 US”);

                                       ItemClassificationCode.setAttribute(“listName”, “Item Classification”);

                                

                                 NodeList nodesItem = node.getChildNodes();

                                if (nodesItem != null) {

                                 for(int k=0;k<nodesItem.getLength();k++){

                                       

                                        Node nodeItem = nodesItem.item(k);

                                        if(nodeItem.getNodeName().equals(“cac:SellersItemIdentification”)){

                                             

                                              NodeList nodesSellersItemIdentification = nodeItem.getChildNodes();

                                             if (nodesSellersItemIdentification != null) {

                                              for(int m=0;m<nodesSellersItemIdentification.getLength();m++){

                                                    

                                                     Node nodeSellersItemIdentification = nodesSellersItemIdentification.item(m);

                                                     if(nodeSellersItemIdentification.getNodeName().equals(“cbc:ID”)){

                                                           //<cbc:ID>2210004</cbc:ID>

                                                            nodeSellersItemIdentification.appendChild(doc.createTextNode(“2210004”));

                                                     }

                                              }

                                             }

                                             

                                        }

                                 }

                                }

                                

                           }

                    }

                    }

                   

            }

                  

            }

           

           

                 // create the xml file

            //transform the DOM Object to an XML File

                 TransformerFactory transformerFactory = TransformerFactory.newInstance();

            Transformer transformer = transformerFactory.newTransformer();

            DOMSource domSource = new DOMSource(doc);

            StreamResult streamResult = new StreamResult(new File(xmlFilePath_ubl21));

 

            // If you use

            // StreamResult result = new StreamResult(System.out);

            // the output will be pushed to the standard output …

            // You can use that for debugging

            transformer.transform(domSource, streamResult);

           

            System.out.println(“Done creating XML File”);

                        

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

      

}