-2

Is there any library or tool for writing XML documents using javascript? I am trying to take some parsed data from an html page and the information needs to be transformed into xml. I was thinking maybe there is a simple method for adding data to an xml node in javascript. I have some jquery that parses the html and gets the information into an array, then I had thought to run through the array and just have placeholders for data. This is closer to C# which I am much more familiar with.

var root = $('<ROOT></ROOT>');
root.append("</description>");
  • Actually, I know my question maybe wasn't phrased so well, but my question was if it was possible to do XML in javascript. I wasn't looking for any specific tool, but if it was even possible. – accessibilitylearner Aug 24 '15 at 20:40

1 Answers1

0

jQuery is enough for you or even the JavaScript itself as you could deal with XML in JavaScript easily as it is DOM object in HTML. In other words I mean you could wrap your XML document in an object directly which will be parsed automatically for you as a DOM object and through which you could find the nodes or elements and their attributes exactly the same way as you are finding an HTML node. Below are some examples.

jQuery Example:

var xmlDocument = jQuery.parseXML("<x><name>Muhammad</name><addr>Cairo, Egypt</addr></x>");

var nameNodes = xmlDocument.documentElement.getElementsByTagName("name");
var surName = jQuery.parseXML("<surName>Soliman</surName>");
var surNode = surName.documentElement;
nameNodes[0].appendChild(surNode);
//exploring ur document now with a new child under name node 
console.log(xmlDocument);

For non-jQuery example, please check this thread.

halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Soliman
  • 21,644
  • 6
  • 109
  • 75