Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working as expected... #14

Open
rajashekhargundeti opened this issue Jun 16, 2016 · 16 comments
Open

Not working as expected... #14

rajashekhargundeti opened this issue Jun 16, 2016 · 16 comments

Comments

@rajashekhargundeti
Copy link

rajashekhargundeti commented Jun 16, 2016

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
Copy link
Collaborator

sterpe commented Jun 17, 2016

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.

@rajashekhargundeti
Copy link
Author

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
#14 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ALREpNP_Dfcyco1OnrZQYsed-5yFTMITks5qMfnbgaJpZM4I3SNh
.

@sterpe
Copy link
Collaborator

sterpe commented Jun 17, 2016

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
#14 (comment), 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
Copy link
Collaborator

sterpe commented Jun 17, 2016

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
Copy link
Collaborator

sterpe commented Jun 17, 2016

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

@rajashekhargundeti
Copy link
Author

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
Copy link
Collaborator

sterpe commented Jun 18, 2016

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

@rajashekhargundeti
Copy link
Author

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

clone this repository and run server.js file

It is terminating the node process after validation.

@rajashekhargundeti
Copy link
Author

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)

@sterpe
Copy link
Collaborator

sterpe commented Jun 21, 2016

@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
Copy link
Collaborator

sterpe commented Jun 21, 2016

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
Copy link
Collaborator

sterpe commented Jun 21, 2016

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

@rondonjon
Copy link

rondonjon commented Jun 9, 2017

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
Copy link

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
Copy link

Nau077 commented Oct 18, 2021

@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
Copy link

Beat-YT commented Nov 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants