showing results for - "working with xml in javascript"
Pedro
20 Jan 2017
1/*
2    This code comes from Vincent Lab
3    And it has a video version linked here: https://www.youtube.com/watch?v=5YQXVgNZvRk
4*/
5
6// Import dependencies
7const fs = require("fs");
8const { parseString, Builder } = require("xml2js");
9
10// Load the XML
11const xml = fs.readFileSync("data.xml").toString();
12parseString(xml, function (err, data) {
13
14    // Show the XML
15    console.log(data);
16
17    // Modify the XML
18    data.people.person[0].$.id = 2;
19
20    // Saved the XML
21    const builder = new Builder();
22    const xml = builder.buildObject(data);
23    fs.writeFileSync("data.xml", xml, function (err, file) {
24        if (err) throw err;
25        console.log("Saved!");
26    });
27
28});
queries leading to this page
xml response in javascriptxml in javascriptjavascript in xmlhow to read xml using javascriptcan you render xml in a javascript filexml in jsjavascript xml representationusing xml dom in javascriptjs working with xmljavascript xml optionsread xml using javascriptcreate xml in javascriptxml dom javascriptxml javascriptjavascript consume xml tutorialxml string to dom javascriptxml request javascriptaccess xml elements javascriptjavascript xml domformat xml using javascriptwhat is javascript xml requesthow to write in an xml file from javascriptshow xml in window javascriptwork with xml in javascriptuse xml files javascriptxml dom manipulation javascriptnew xml javascriptjavascript xml how to write xml file in jsworking with xml in javascriptusing javascript to xml uses both javascript and xml 3fjavascript xmlwhat is xml syntax in javascriptxml js javascripthow to handle xml in javascriptrepresenting xml document in javascriptjavascript xml functionsjavascript xml tutorialxml inject script javascriptmake xml file using javascriptread xml in javascriptjs xmlformat xml with javascripthow to read an xml file in javascripthtml read from xml with javascripthow to render xml type html javascriptpresent xml file on web javascripthow to read xml javascriptfile become xml in javascriptxml javascript domjavascript create xml from stringrequest xml javascriptcreate xml file in javascriptjavascript xml requestxml inject javascriptjavascripnt in xmlcreate xml javascriptwrite xml in javascriptread xml tags in javascriptworking xml jsload xml in javascriptread xml with javascriptwhat is javascript xmldefinition of xml in javascriptcreate xml document in javascripthow to write xml in javascriptcreate xml with javascriptusing xml with javascripthow to work with xml javascriptfuntion to return xml in javascripthow to use xml in javascriptshow xml file with javascriptread xml javascriptjavacript xmlhow does js handle xmlformat xml in javascriptuse xml with javascript browserjavascript to read xmlxml string to xml in javascriptdisplaying xml using html and jsrwork with xml in javascriptreading xml with javascriptxml request in javascriptwork with xml in jsusing javascript to read xmlwhat does javascript xml meanopen xml in html with javascriptaccessing xml elements in javascriptjavasript xmljavascript xml operationshow to read xml in jsworking with xml in javascript