Questions tagged [xml2js]

Simple XML to JavaScript object converter

Simple XML to JavaScript object converter. It supports bi-directional conversion. Uses sax-js and xmlbuilder-js.

More information on project page.

141 questions
0
votes
1 answer

Trouble getting XML file values w/ JS

I need to pass some items from an XML file, as parameters to the res.renderer() function (shown further below) . I currently can achieve this with this sample XML: Sample.xml Belgian Waffles
0
votes
1 answer

Not getting expected JSON format when using xml2js, can it be fixed?

When I try to convert an XML file (requested from an external server) to JSON, it seems to me that xml2json does convert it however, not to a correct JSON file. Is there something that needs to be adjusted. I seem to be missing quotes for the…
Mihaly
  • 303
  • 1
  • 3
  • 14
0
votes
2 answers

XML2JS conversion in nodejs

Hi I need one help When I am using xml2js node js lib. I am able to convert the XML to JSON object however when I am iterating JSON element I can see the '$': as few of the key elements. Is there a way I can eliminate the $ key ?
Mohsin Khan
  • 90
  • 2
  • 11
0
votes
2 answers

How to parse xml using JavaScript and identify elements based on attributes

I am using xml2js to convert an xml file into a javascript object. I need to identify attributes within element tags in the xml file and manipulate the matching element(s). For example, I have some a property element in test.xml: ...
arctic
  • 609
  • 3
  • 11
  • 19
0
votes
1 answer

How to present XML in a Flat List react native

I have a React Native application and I want to: Fetch data in a XML format from here Translate it to JSON using react-native-xml2js Display the JSON data in a FlatList Here's my source code import React, { useEffect, useState } from…
Tom Wicks
  • 785
  • 2
  • 11
  • 28
0
votes
1 answer

How to process/read a large (3gb) xml file in node js?

I want to read a large xml file and store the data in database. I tried xml2js but am getting error as Error: Cannot create a string longer than 0x3fffffe7 characters. I would like to know the best practice for processing xml file, whether can i…
Vignesh
  • 1
  • 1
  • 1
  • 1
0
votes
0 answers

Converting a particular key into Array of object instead of an object

I have a service which returns XML resposne. I am using xml2JS to parse the XML to JSON. The XML looks like - custom false 1 55705 Reference…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/javascript" class="post-tag grid--cell" title="show questions tagged 'javascript'" rel="tag">javascript</a> <a href="../../questions/tagged/arrays" class="post-tag grid--cell" title="show questions tagged 'arrays'" rel="tag">arrays</a> <a href="../../questions/tagged/json" class="post-tag grid--cell" title="show questions tagged 'json'" rel="tag">json</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Nov 23 '20 at 11:59">asked Nov 23 '20 at 11:59</time> <a href="../../users/12878931/rohit-srivastava" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/12878931.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Rohit Srivastava" /> </a> <div class="s-user-card--info"> <a href="../../users/12878931/rohit-srivastava" class="s-user-card--link">Rohit Srivastava</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">1</li> <li class="s-award-bling s-award-bling__bronze" title="3 bronze badges">3</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-64340617"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>0</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>2</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/64340617/issue-parsing-xliff-with-node-xml-parser" class="question-hyperlink">Issue parsing XLIFF with node XML parser</a></h3> <div class="excerpt">Im trying to parse XLIFF file using xml2js library. All is working fine but if I have something like that: <source>Welcome to <x id="INTERPOLATION" equiv-text="{{ title }}"/> my friend</source> I will get [{"_":"Welcome to my…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/node.js" class="post-tag grid--cell" title="show questions tagged 'node.js'" rel="tag">node.js</a> <a href="../../questions/tagged/xml" class="post-tag grid--cell" title="show questions tagged 'xml'" rel="tag">xml</a> <a href="../../questions/tagged/xliff" class="post-tag grid--cell" title="show questions tagged 'xliff'" rel="tag">xliff</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Oct 13 '20 at 17:55">asked Oct 13 '20 at 17:55</time> <a href="../../users/967588/andrei-v" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/967588.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Andrei V" /> </a> <div class="s-user-card--info"> <a href="../../users/967588/andrei-v" class="s-user-card--link">Andrei V</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">1,468</li> <li class="s-award-bling s-award-bling__gold" title="3 gold badges">3</li> <li class="s-award-bling s-award-bling__silver" title="17 silver badges">17</li> <li class="s-award-bling s-award-bling__bronze" title="32 bronze badges">32</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-64183286"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>0</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>1</strong> answer </div> </div> </div> <div class="summary"> <h3><a href="../../questions/64183286/cannot-read-property-parser-of-undefined-promise-error" class="question-hyperlink">Cannot read property 'Parser' of undefined promise error</a></h3> <div class="excerpt">I was parsing some data via API my code for the parsing is given below, parseXML(data) { return new Promise((resolve) => { var k: string | number, arr = [], parser = new xml2js.Parser({ trim: true, …</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/javascript" class="post-tag grid--cell" title="show questions tagged 'javascript'" rel="tag">javascript</a> <a href="../../questions/tagged/angular" class="post-tag grid--cell" title="show questions tagged 'angular'" rel="tag">angular</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Oct 03 '20 at 10:38">asked Oct 03 '20 at 10:38</time> <a href="../../users/10308630/md-nasirul-islam" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/10308630.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="MD Nasirul Islam" /> </a> <div class="s-user-card--info"> <a href="../../users/10308630/md-nasirul-islam" class="s-user-card--link">MD Nasirul Islam</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">501</li> <li class="s-award-bling s-award-bling__silver" title="5 silver badges">5</li> <li class="s-award-bling s-award-bling__bronze" title="17 bronze badges">17</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-64047034"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>0</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>2</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/64047034/arrays-returned-by-xml2js-do-not-maintain-all-the-order" class="question-hyperlink">Arrays returned by xml2js do not maintain all the order</a></h3> <div class="excerpt">When xml elements are bundled some of the order is lost. For example, the xml I'm reading has elements that look like: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <b> <c n="1"> <v n="1"> <w>w1</w> <w>w2</w> …</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/node.js" class="post-tag grid--cell" title="show questions tagged 'node.js'" rel="tag">node.js</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Sep 24 '20 at 13:01">asked Sep 24 '20 at 13:01</time> <a href="../../users/13849098/rodney-east" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/13849098.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Rodney East" /> </a> <div class="s-user-card--info"> <a href="../../users/13849098/rodney-east" class="s-user-card--link">Rodney East</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">21</li> <li class="s-award-bling s-award-bling__bronze" title="2 bronze badges">2</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-63926462"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>0</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>1</strong> answer </div> </div> </div> <div class="summary"> <h3><a href="../../questions/63926462/parse-xml-from-an-api-in-nuxt-using-xml2js" class="question-hyperlink">Parse XML from an API in Nuxt using XML2JS</a></h3> <div class="excerpt">I'm trying to Loop through the API in nuxt using XML2JS and then looping through the data to display it within an html file. It's working when console logged but it's not looping through within the HTML. There arent any errors its, just blank and…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/vue.js" class="post-tag grid--cell" title="show questions tagged 'vue.js'" rel="tag">vue.js</a> <a href="../../questions/tagged/nuxt.js" class="post-tag grid--cell" title="show questions tagged 'nuxt.js'" rel="tag">nuxt.js</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Sep 16 '20 at 19:02">asked Sep 16 '20 at 19:02</time> <a href="../../users/3751529/henshall" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/3751529.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Henshall" /> </a> <div class="s-user-card--info"> <a href="../../users/3751529/henshall" class="s-user-card--link">Henshall</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">169</li> <li class="s-award-bling s-award-bling__silver" title="1 silver badges">1</li> <li class="s-award-bling s-award-bling__bronze" title="20 bronze badges">20</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-63833783"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>0</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>1</strong> answer </div> </div> </div> <div class="summary"> <h3><a href="../../questions/63833783/how-do-you-add-attribute-to-array-element-with-xml2js" class="question-hyperlink">How do you add attribute to array element with xml2js?</a></h3> <div class="excerpt">I'm trying to figure out how to add attributes to an array element I get an error Error: Invalid character in name when trying to build the following XML from an object. <?xml version="1.0" encoding="UTF-8"?> <Requests xmlns="http://example.com"> …</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/node.js" class="post-tag grid--cell" title="show questions tagged 'node.js'" rel="tag">node.js</a> <a href="../../questions/tagged/json" class="post-tag grid--cell" title="show questions tagged 'json'" rel="tag">json</a> <a href="../../questions/tagged/xml" class="post-tag grid--cell" title="show questions tagged 'xml'" rel="tag">xml</a> <a href="../../questions/tagged/typescript" class="post-tag grid--cell" title="show questions tagged 'typescript'" rel="tag">typescript</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Sep 10 '20 at 16:18">asked Sep 10 '20 at 16:18</time> <a href="../../users/4650224/skedge" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/4650224.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Skedge" /> </a> <div class="s-user-card--info"> <a href="../../users/4650224/skedge" class="s-user-card--link">Skedge</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">89</li> <li class="s-award-bling s-award-bling__silver" title="1 silver badges">1</li> <li class="s-award-bling s-award-bling__bronze" title="10 bronze badges">10</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-63106691"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>0</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>3</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/63106691/object-property-coming-up-as-undefined-after-assigning-with-an-async-fetch" class="question-hyperlink">Object property coming up as undefined after assigning with an async fetch</a></h3> <div class="excerpt">I'm having some trouble with adding a key to an object as seen here: const recursiveFetchAndWait = useCallback( (url) => { setLoading(true); fetch(url) .then(async response => { …</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/javascript" class="post-tag grid--cell" title="show questions tagged 'javascript'" rel="tag">javascript</a> <a href="../../questions/tagged/reactjs" class="post-tag grid--cell" title="show questions tagged 'reactjs'" rel="tag">reactjs</a> <a href="../../questions/tagged/object" class="post-tag grid--cell" title="show questions tagged 'object'" rel="tag">object</a> <a href="../../questions/tagged/async-await" class="post-tag grid--cell" title="show questions tagged 'async-await'" rel="tag">async-await</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Jul 26 '20 at 23:08">asked Jul 26 '20 at 23:08</time> <a href="../../users/14000052/gamerkingfaiz" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/14000052.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="GamerKingFaiz" /> </a> <div class="s-user-card--info"> <a href="../../users/14000052/gamerkingfaiz" class="s-user-card--link">GamerKingFaiz</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">21</li> <li class="s-award-bling s-award-bling__bronze" title="7 bronze badges">7</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-62675615"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>0</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>1</strong> answer </div> </div> </div> <div class="summary"> <h3><a href="../../questions/62675615/extracting-info-from-nodejs-xml2js-result" class="question-hyperlink">Extracting info from nodejs xml2js 'result'</a></h3> <div class="excerpt">Using the xml2js nodejs module, I've managed to extract from a (large!) xml document, using the following code; var fs = require('fs'), parseString = require('xml2js').parseString, request = require('request'); …</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/javascript" class="post-tag grid--cell" title="show questions tagged 'javascript'" rel="tag">javascript</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Jul 01 '20 at 11:16">asked Jul 01 '20 at 11:16</time> <a href="../../users/9658099/darren-harley" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/9658099.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Darren Harley" /> </a> <div class="s-user-card--info"> <a href="../../users/9658099/darren-harley" class="s-user-card--link">Darren Harley</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">75</li> <li class="s-award-bling s-award-bling__silver" title="1 silver badges">1</li> <li class="s-award-bling s-award-bling__bronze" title="18 bronze badges">18</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-62596893"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>0</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>1</strong> answer </div> </div> </div> <div class="summary"> <h3><a href="../../questions/62596893/angular-10-update-and-xml2js" class="question-hyperlink">Angular 10 Update and xml2js</a></h3> <div class="excerpt">Hi I did the update to Angular 10 right now.. and i am receiving this error on ng serve ERROR in ./node_modules/xml2js/lib/parser.js Module not found: Error: Can't resolve 'timers' in '/src/WebApp/node_modules/xml2js/lib' This is the line …</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/angular" class="post-tag grid--cell" title="show questions tagged 'angular'" rel="tag">angular</a> <a href="../../questions/tagged/npm" class="post-tag grid--cell" title="show questions tagged 'npm'" rel="tag">npm</a> <a href="../../questions/tagged/node-modules" class="post-tag grid--cell" title="show questions tagged 'node-modules'" rel="tag">node-modules</a> <a href="../../questions/tagged/xml2js" class="post-tag grid--cell" title="show questions tagged 'xml2js'" rel="tag">xml2js</a> <a href="../../questions/tagged/ngx-xml2json" class="post-tag grid--cell" title="show questions tagged 'ngx-xml2json'" rel="tag">ngx-xml2json</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Jun 26 '20 at 14:26">asked Jun 26 '20 at 14:26</time> <a href="../../users/11948390/ikkyy" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/11948390.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Ikkyy" /> </a> <div class="s-user-card--info"> <a href="../../users/11948390/ikkyy" class="s-user-card--link">Ikkyy</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">66</li> <li class="s-award-bling s-award-bling__bronze" title="13 bronze badges">13</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="s-pagination pager fr"> <a class="s-pagination--item" href="../../questions/tagged/xml2js_page=5" rel="prev" title="Go to page 5">Prev </a> <a class="s-pagination--item" href="../../questions/tagged/xml2js_page=1" rel="" title="Go to page 1">1</a> <a class="s-pagination--item" href="../../questions/tagged/xml2js_page=2" rel="" title="Go to page 2">2</a> <a class="s-pagination--item" href="../../questions/tagged/xml2js_page=3" rel="" title="Go to page 3">3</a> <div class="s-pagination--item s-pagination--item__clear">…</div> <a class="s-pagination--item" href="../../questions/tagged/xml2js_page=9" rel="" title="Go to page 9">9</a> <a class="s-pagination--item" href="../../questions/tagged/xml2js_page=10" rel="" title="Go to page 10">10</a> <a class="s-pagination--item" href="../../questions/tagged/xml2js_page=7" rel="next" title="Go to page 7"> Next</a> </div> </div> </div> </div> </div> <script src="../../static/js/stack-icons.js"></script> <script src="../../static/js/fromnow.js"></script> </body> </html>