1

I am new to NodeJS, and I've setup a little webserver. Now I want to be able to use my old html files, which at server side on PHP, which I now want to translate to JavaScript. I have a function in my PHP files, which retrieves information from MySQL and turns it into a XML document and sends it to the client.

So now I want to build a XML 'file' using JavaScript. I am familiar with that, because the JavaScript on client-side would turn the XML file into a table. So I searched the internet and found nothing about:

  1. Beginning a XML file (so not importing one)
  2. Building an XML file like you handling the DOM in the browser, with that I mean being able to use functions like getElementsByTagName(), createElement and setAttribute() for instance.

My excuses where my English is not the best, 'cause I'm a dutch guy. I hope that doesn't influence an answer :).

Thanks,

4
  • Hello, you should have started with a search on npm, and maybe then realize you are going the wrong way ;-) If you come in the nodeJS world, why not giving up on XML and use JSON? Commented Oct 23, 2014 at 14:15
  • I could do that, the reason I wanted to stick to XML is because the client-side is made for XML; many of my JavaScript code in my HTML files deal with XML, and I prefer not to rewrite them too. Commented Oct 23, 2014 at 14:19
  • Well then you should look at npmjs.org/package/xml for example and then comme back if you have problem with it. Commented Oct 23, 2014 at 14:31
  • possible duplicate of Node.js: How to create XML files Commented Sep 1, 2015 at 2:38

3 Answers 3

2

Here is an package called xmldom that provides an implementation of the DOM Api for node.js

npm install xmldom

If you want support for XPath with document.evaluate(), check out xpath package.

npm install xpath
Sign up to request clarification or add additional context in comments.

Comments

1

I recomand you use xmlbuilder package.

npm install xmlbuilder

the full documentation is here

Comments

0

I'd recommend using damn-simple-xml. It's really well documented. You'll work with your javascript object until you need to serialized it to XML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.