different parser under node.js
GoogleCodeExporter opened this issue · comments
Google Code Exporter commented
What steps will reproduce the problem?
1. Install node.js
2. Install xmldom with this command:
npm install xmldom
3. use the following code:
var window={};
var DOMParser = require('xmldom').DOMParser;
window.DOMParser=DOMParser;
//do the usual x2js stuff
What is the expected output? What do you see instead?
I expect normal functionality but it blows up under server-side javascript.
What version of the product are you using? On what operating system?
node.js 0.8.12 on windows 7.
Please provide any additional information below.
Change the code from this (start at line 233):
if (window.DOMParser) {
var parser=new DOMParser();
xmlDoc = parser.parseFromString( xmlDocStr, "text/xml" );
}
to this:
if (window.DOMParser) {
var parser=new window.DOMParser();
xmlDoc = parser.parseFromString( xmlDocStr, "text/xml" );
}
Original issue reported on code.google.com by pauled...@gmail.com
on 18 Oct 2012 at 1:54
Google Code Exporter commented
Working on it
Thank you for submit issue!
Original comment by abdulla....@gmail.com
on 18 Oct 2012 at 5:49
- Changed state: Accepted
Google Code Exporter commented
Fixed in 1.0.8.
Thank you!
Original comment by abdulla....@gmail.com
on 18 Oct 2012 at 8:59
- Changed state: Done
Google Code Exporter commented
[deleted comment]
Google Code Exporter commented
[deleted comment]
Google Code Exporter commented
[deleted comment]
Google Code Exporter commented
Hi Paul,
How did you loaded x2js file in to nodejs? I am getting final output as [object
Object]
here is my service code:
function x2js(req, res) {
var window={};
var DOMParser = require('xmldom').DOMParser;
var XMLSerializer = require('xmldom').XMLSerializer;
window.DOMParser=DOMParser;
var x2jsModule = require("./x2js.js");
var x2jsObject = new x2jsModule.X2JS()
// JSON to XML string
var xmlDocStr = x2jsObject.json2xml_str(
{
MyRoot : {
MyChild : 'my_child_value',
MyAnotherChild : 10,
MyArray : [ 'test', 'test2' ],
MyArrayRecords : [
{
ttt : 'vvvv'
},
{
ttt : 'vvvv2'
}
]
}
}
);
var xmlText = new XMLSerializer().serializeToString(xmlDocStr);
console.log(xmlText);its returning [object Object]
console.log(xmlText);its returning ??
res.send(xmlText);
};
and the way converted X2JS() to nodejs module is
exports.X2JS = function(config) {
Thanks
Peter
Original comment by peterkr2...@gmail.com
on 9 Dec 2014 at 4:23