Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.88k stars 604 forks source link

Invalid character in name - buildObject #639

Open oscar-developer opened 2 years ago

oscar-developer commented 2 years ago

Hi Leonidas, I have a problem when trying to convert a json to xml. the "Invoice" tag needs to be an array since I will dynamically add more of the same elements.

var JsonFact = {
'Invoice':[{ '$' : { "listURI":"urn:pe:gob:sunat:cpe:see:catalogos:catalogo01", "listName":"Tipo de Documento", "listAgencyName": "PE:SUNAT", "listID":"0101" } }, "cbc:item":"1", "cbc:item":"2", "cbc:item":"3" ] }; //JsonFact =JsonFact.Invoice.push({"cbc:item":"4"}); //JsonFact =JsonFact.Invoice.push({"cbc:item":"5"});

var builder = new xml2js.Builder( { headless: false, renderOpts: { pretty: true } ,xmldec: {version: "1.0"}}); var xml = builder.buildObject(JsonFact); then throw the message "Invalid character in name --> $ "

Could you please guide me how to solve it, thanks Leonidas.

oscar-developer commented 2 years ago

Solucionado, primero se agregan todas las etiquetas que se necesitan y se agregan poco a poco las vacias[].

satyajitnayk commented 10 months ago

Translation: Solved, first all the tags that are needed are added and the empty ones[] are added little by little.