kripken / xml.js

Port of libxml to JavaScript using Emscripten
Other
174 stars 67 forks source link

Not working as expected... #14

Open rajashekhargundeti opened 8 years ago

rajashekhargundeti commented 8 years ago

Hi,

I'm able to successfully compile it on ubuntu 14. but when i execute the following code, it is getting terminated without spitting any error, below is my code:

fs = require('fs'); xml1 = fs.readFileSync('./test/test.xml'); xsd1 = fs.readFileSync('./test/test.xsd'); xmllint = eval(''+fs.readFileSync('./xmllint.js')); result = xmllint.validateXML({xml: xml1.toString(), schema: xsd1.toString()}); console.log("result: " + result);

xsd file is :

image

xml file is:

image

sterpe commented 8 years ago

Try

xmllint = require('./xmllint.js')

Sent from my iPhone

On Jun 16, 2016, at 4:23 AM, rajashekhargundeti notifications@github.com wrote:

Hi,

I'm able to successfully compile it on ubuntu 14. but when i execute the following code, it is getting terminated without spitting any error, below is my code:

fs = require('fs'); xml1 = fs.readFileSync('./test/test.xml'); xsd1 = fs.readFileSync('./test/test.xsd'); xmllint = eval(''+fs.readFileSync('./xmllint.js')); result = xmllint.validateXML({xml: xml1.toString(), schema: xsd1.toString()}); console.log("result: " + result);

my test.xml is :

<?xml version="1.0"?>

Writer The First Book Fiction 44.95 2000-10-01 An amazing story of nothing.

Poet The Poet's First Poem Poem 24.95 2000-10-01 Least poetic poems. /x:books

my xsd is:

targetNamespace="urn:books" xmlns:bks="urn:books">

xsd:sequence /xsd:sequence /xsd:complexType xsd:sequence /xsd:sequence /xsd:complexType /xsd:schema — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
rajashekhargundeti commented 8 years ago

I tried that approach first, same results.

On Fri, Jun 17, 2016 at 7:05 AM, Steve Terpe notifications@github.com wrote:

Try

xmllint = require('./xmllint.js')

Sent from my iPhone

On Jun 16, 2016, at 4:23 AM, rajashekhargundeti < notifications@github.com> wrote:

Hi,

I'm able to successfully compile it on ubuntu 14. but when i execute the following code, it is getting terminated without spitting any error, below is my code:

fs = require('fs'); xml1 = fs.readFileSync('./test/test.xml'); xsd1 = fs.readFileSync('./test/test.xsd'); xmllint = eval(''+fs.readFileSync('./xmllint.js')); result = xmllint.validateXML({xml: xml1.toString(), schema: xsd1.toString()}); console.log("result: " + result);

my test.xml is :

<?xml version="1.0"?>

Writer The First Book Fiction 44.95 2000-10-01 An amazing story of nothing.

Poet The Poet's First Poem Poem 24.95 2000-10-01 Least poetic poems. /x:books

my xsd is:

targetNamespace="urn:books" xmlns:bks="urn:books">

xsd:sequence /xsd:sequence /xsd:complexType xsd:sequence /xsd:sequence /xsd:complexType /xsd:schema — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kripken/xml.js/issues/14#issuecomment-226659549, or mute the thread https://github.com/notifications/unsubscribe/ALREpNP_Dfcyco1OnrZQYsed-5yFTMITks5qMfnbgaJpZM4I3SNh .

sterpe commented 8 years ago

Can you set up a repo that reproduces the problem?

Sent from my iPhone

On Jun 16, 2016, at 10:44 PM, rajashekhargundeti notifications@github.com wrote:

I tried that approach first, same results.

On Fri, Jun 17, 2016 at 7:05 AM, Steve Terpe notifications@github.com wrote:

Try

xmllint = require('./xmllint.js')

Sent from my iPhone

On Jun 16, 2016, at 4:23 AM, rajashekhargundeti < notifications@github.com> wrote:

Hi,

I'm able to successfully compile it on ubuntu 14. but when i execute the following code, it is getting terminated without spitting any error, below is my code:

fs = require('fs'); xml1 = fs.readFileSync('./test/test.xml'); xsd1 = fs.readFileSync('./test/test.xsd'); xmllint = eval(''+fs.readFileSync('./xmllint.js')); result = xmllint.validateXML({xml: xml1.toString(), schema: xsd1.toString()}); console.log("result: " + result);

my test.xml is :

<?xml version="1.0"?>

Writer The First Book Fiction 44.95 2000-10-01 An amazing story of nothing.

Poet The Poet's First Poem Poem 24.95 2000-10-01 Least poetic poems. /x:books

my xsd is:

targetNamespace="urn:books" xmlns:bks="urn:books">

xsd:sequence /xsd:sequence /xsd:complexType xsd:sequence /xsd:sequence /xsd:complexType /xsd:schema — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kripken/xml.js/issues/14#issuecomment-226659549, or mute the thread https://github.com/notifications/unsubscribe/ALREpNP_Dfcyco1OnrZQYsed-5yFTMITks5qMfnbgaJpZM4I3SNh .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

sterpe commented 8 years ago

Also, what happens if you don't build it from the source, and just use package available from npm:

npm i xmllint

?

Emscripten changes quite a bit, it's possible that there have been breaking changes and this no longer compiles correctly with the latest version of emscripten SDK.

sterpe commented 8 years ago

This should compile correctly with emscripten SDK 1.29.0 see #4.

rajashekhargundeti commented 8 years ago

same result if i use xmllint module:

image

One thing that is working for me is : the code that i got from http://syssgx.github.io/xml.js/js/xmllint.js.

I took this and tried. it is working as expected. I have an issue with the script is that it is writing the output directly to the console, but i need to keep the result to include it in my project.

image

sterpe commented 8 years ago

If you can put together a small repo that reproduces the issue I will look into this further.

rajashekhargundeti commented 8 years ago

https://github.com/rajashekhargundeti/xmllint-test

clone this repository and run server.js file

It is terminating the node process after validation.

rajashekhargundeti commented 8 years ago

I tested this with http module. same issue.

image

contents of test file:

image

It is crashing the node process with this exception:

gundetir@gundetir-VirtualBox:~/workspace/nodejs/client/test$ node http-test.js Server is listening

result: {"errors":null} Caught exception: TypeError: xmllint.validateXML is not a function /media/sf_nodejs/client/nodemodules/xmllint/xmllint.js:11 Module["preRun"]=(function(){var i;for(i=0;i<(1||Module["xml"].length);i++){FS.createDataFile("/","file"+i+".xml",Module"intArrayFromString",true,true)}for(i=0;i<Module["schema"].length;i++){FS.createDataFile("/","file"+i+".xsd",Module"intArrayFromString",true,true)}});Module.arguments=["--noout"];((function(){var i;if("[object Array]"!==Object.prototype.toString.call(Module["schema"])){Module["schema"]=[Module["schema"]]}if("[object Array]"!==Object.prototype.toString.call(Module["xml"])){Module["xml"]=[Module["xml"]]}for(i=0;i<Module["schema"].length;i++){Module.arguments.push("--schema");Module.arguments.push("file"+i+".xsd")}for(i=0;i<(1||Module["xml"].length);i++){Module.arguments.push("file_"+i+".xml")}}))();Module["return"]="";Module["stdout"]=Module["stderr"]=(function(code){Module["return"]+=String.fromCharCode(code)});var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};va

TypeError: xmllint.validateXML is not a function at Server. (/media/sf_nodejs/client/test/http-test.js:10:22) at emitTwo (events.js:87:13) at Server.emit (events.js:172:7) at HTTPParser.parserOnIncoming as onIncoming at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)

sterpe commented 8 years ago

@rajashekhargundeti This seems to be similar to #11. Unfortunately, I don't think anyone has a solution for this yet. It looks like what you are trying to do is use xmllint on a server. I would recommend using child_process.spawn|exec to shell out to the C version of xmllint. It is far more powerful.

sterpe commented 8 years ago

It seems like certain types of .xml & .xsd can have problems because they specify pathing relative to each other but that pathing does not correspond to the virtualFS filesystem that emscripten uses

For example ./test/test.xml & ./test/test.xsd behave correctly

sterpe commented 8 years ago

http://syssgx.github.io/xml.js/js/xmllint.js was compiled with an earlier version of emscripten perhaps there have been internal changes.

rondonjon commented 7 years ago

Same problem here. I had added xmllint to my unit tests, and noticed that they started to terminate randomly. After removing xmllint, the unit tests worked as intended.

italobologna commented 3 years ago

Guess this is really an old topic, but I had the same issue with the node application and did a workaround to the problem by invoking a node child process to call the library.

Solution was mostly:

For the main code:

  return new Promise(resolve => {
    const lint = fork(`${ __dirname }/xmllint.js`);
    lint.on('message', resolve);
    lint.send({ xml: xmlString, xsd: xsdString });
  });

As the auxiliary child process:

const { validateXML } = require('xmllint');

const evaluateXml = (xml, xsd) => {
  return validateXML({ xml: xml, schema: xsd });
};

process.on('message', ({ xml, xsd }) => {
  process.send(evaluateXml(xml, xsd));
});
Nau077 commented 2 years ago

@italobologna

Hello! Thanks for solution, with your code this library is working. Why this information is not written at readme? And what is the reason for this behavior of the library, why we need child process, do you remember?

Beat-YT commented 2 years ago

You can use my fork https://github.com/Beat-YT/xml.js