0

I am developing a javascript file while i will be using as external file in my html. In this js file I want to create an xml object but do not know how to use jquery in here and javascripts functions also do not work here. I have tried below as work around,

var xmlString = "<root></root>";
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlString, "text/xml");

and

var XML = new XMLWriter();

Nothing worked out. I think i'll work when i include like,

But i want to develop external js file independently which is like,

var fs = require('fs'); 
//// and some other code
/// write this xml to a file
fs.writeFile("GSG_features3.xml", result, function(err) {
    if(err) {
        return console.log(err);
    }
       console.log("The file was saved!");
});
//// and some other code

i am executing my script node D:\Work > node myexternaljs.js

How can i achieve this?

James Z
  • 12,209
  • 10
  • 24
  • 44
usersam
  • 1,125
  • 4
  • 27
  • 54
  • https://api.jquery.com/jQuery.parseXML/ – Axnyff Nov 21 '17 at 15:35
  • This works but need to include jquery. How to include jquery in js file that is not known to me. – usersam Nov 21 '17 at 15:40
  • What is your plateform, browser or nodejs? For the browser you can either load the jquery script before your script (it will then be accessible with window.jQuery or window.$) or you can use a module bundler (like webpack , browserify or rollup). If nodejs or a bundler, you need to npm install jquery and then do `var jQuery = require('jquery');` – Axnyff Nov 21 '17 at 15:51
  • Why do you need jquery exactly? If your running node this is more suitable: https://stackoverflow.com/questions/14890655/the-best-node-module-for-xml-parsing – ChristianMurschall Nov 21 '17 at 15:51
  • I do not need jquery exactly. i just want to create an xml object and do some manipulations like find child, add child, add attributes .. only. any other option is also acceptable. – usersam Nov 22 '17 at 04:22

0 Answers0