Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Uso de xml2js para crear nodos de forma dinámica en función de los datos consultados; se necesitan <value>algunos datos</value> de cero a muchas veces

Estoy usando xmlbuilder para generar un archivo xml de forma dinámica a partir de los datos de una consulta. Para el nodo de atributo personalizado retailTypeId, necesito recorrer una matriz de retailTypeIds y agregar un nodo de valor para cada uno en la matriz.

Todo lo que hago para inyectar un bucle for para determinar qué valores se necesitan para cada nuevo nodo de tienda rompe el código. En este momento estoy insertando el primero en una posible cadena de valores separados por el punto y coma. Lo he intentado todo lo que se me ocurre y no puedo hacerlo funcionar. ¿Alguien puede ayudar?

 xml.att('xmlns', 'http://www.demandware.com/xml/impex/store/2007-04-30') .ele('store', {'store-id': storeRecord.ID}) .ele('name', storeRecord.LOCATION_NAME__C).up() .ele('custom-attributes') .ele('custom-attribute', { 'attribute-id': 'retailerTypeId', 'xml:lang': 'x-default' }) .ele('value', storeRecord.RETAILER_TYPE__C.split(';')[0]).up() .up() .up() .up() xml.end({ pretty: true});` I was attempting something like this but don't have the syntax correct as it closes the custom-attribute node: .ele('custom-attribute', { 'attribute-id': 'retailerTypeId','xml:lang' : 'x-default' }) for (var i = 0; i < retailerTypes.length; i++) { xml.ele('value').txt(retailerTypes[i]) .up() } .up()
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

cree un fragmento XML con bucle for y luego agréguelo al XML principal:

 xml.att('xmlns', 'http://www.demandware.com/xml/impex/store/2007-04-30') .ele('store', {'store-id': storeRecord.ID}) .ele('name', storeRecord.LOCATION_NAME__C).up() const custom = xmlbuilder.create('custom-attributes'); for (let i = 0; i < retailerTypes.length; i++) { custom .ele('custom-attribute', { 'attribute-id': 'retailerTypeId', 'xml:lang': 'x-default' }) .ele('value', retailerTypes[i]).up().up() } xml.importDocument(custom); xml.end({ pretty: true});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!