xml.js icon indicating copy to clipboard operation
xml.js copied to clipboard

Not working as expected...

Open rajashekhargundeti opened this issue 9 years ago • 16 comments

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

rajashekhargundeti avatar Jun 16 '16 11:06 rajashekhargundeti

Try

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

Sent from my iPhone

On Jun 16, 2016, at 4:23 AM, rajashekhargundeti [email protected] 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 :

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:element name="books" type="bks:BooksForm" />

<xsd:complexType name="BooksForm"> xsd:sequence <xsd:element name="book" type="bks:BookForm" minOccurs="0" maxOccurs="unbounded" /> /xsd:sequence /xsd:complexType

<xsd:complexType name="BookForm"> xsd:sequence <xsd:element name="author" type="xsd:string" /> <xsd:element name="title" type="xsd:string" /> <xsd:element name="genre" type="xsd:string" /> <xsd:element name="price" type="xsd:float" /> <xsd:element name="pub_date" type="xsd:date" /> <xsd:element name="review" type="xsd:string" /> /xsd:sequence <xsd:attribute name="id" type="xsd:string" /> /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.

sterpe avatar Jun 17 '16 01:06 sterpe

I tried that approach first, same results.

On Fri, Jun 17, 2016 at 7:05 AM, Steve Terpe [email protected] wrote:

Try

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

Sent from my iPhone

On Jun 16, 2016, at 4:23 AM, rajashekhargundeti < [email protected]> 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 :

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:element name="books" type="bks:BooksForm" />

<xsd:complexType name="BooksForm"> xsd:sequence <xsd:element name="book" type="bks:BookForm" minOccurs="0" maxOccurs="unbounded" /> /xsd:sequence /xsd:complexType

<xsd:complexType name="BookForm"> xsd:sequence <xsd:element name="author" type="xsd:string" /> <xsd:element name="title" type="xsd:string" /> <xsd:element name="genre" type="xsd:string" /> <xsd:element name="price" type="xsd:float" /> <xsd:element name="pub_date" type="xsd:date" /> <xsd:element name="review" type="xsd:string" /> /xsd:sequence <xsd:attribute name="id" type="xsd:string" /> /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 .

rajashekhargundeti avatar Jun 17 '16 05:06 rajashekhargundeti

Can you set up a repo that reproduces the problem?

Sent from my iPhone

On Jun 16, 2016, at 10:44 PM, rajashekhargundeti [email protected] wrote:

I tried that approach first, same results.

On Fri, Jun 17, 2016 at 7:05 AM, Steve Terpe [email protected] wrote:

Try

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

Sent from my iPhone

On Jun 16, 2016, at 4:23 AM, rajashekhargundeti < [email protected]> 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 :

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:element name="books" type="bks:BooksForm" />

<xsd:complexType name="BooksForm"> xsd:sequence <xsd:element name="book" type="bks:BookForm" minOccurs="0" maxOccurs="unbounded" /> /xsd:sequence /xsd:complexType

<xsd:complexType name="BookForm"> xsd:sequence <xsd:element name="author" type="xsd:string" /> <xsd:element name="title" type="xsd:string" /> <xsd:element name="genre" type="xsd:string" /> <xsd:element name="price" type="xsd:float" /> <xsd:element name="pub_date" type="xsd:date" /> <xsd:element name="review" type="xsd:string" /> /xsd:sequence <xsd:attribute name="id" type="xsd:string" /> /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 avatar Jun 17 '16 14:06 sterpe

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 avatar Jun 17 '16 15:06 sterpe

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

sterpe avatar Jun 17 '16 15:06 sterpe

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

rajashekhargundeti avatar Jun 18 '16 07:06 rajashekhargundeti

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

sterpe avatar Jun 18 '16 14:06 sterpe

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

clone this repository and run server.js file

It is terminating the node process after validation.

rajashekhargundeti avatar Jun 21 '16 09:06 rajashekhargundeti

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/node_modules/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)

rajashekhargundeti avatar Jun 21 '16 09:06 rajashekhargundeti

@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 avatar Jun 21 '16 15:06 sterpe

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 avatar Jun 21 '16 15:06 sterpe

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

sterpe avatar Jun 21 '16 15:06 sterpe

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.

rondonjon avatar Jun 09 '17 08:06 rondonjon

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));
});

italobologna avatar Oct 11 '20 14:10 italobologna

@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?

Nau077 avatar Oct 18 '21 11:10 Nau077

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

Beat-YT avatar Nov 20 '21 03:11 Beat-YT