Not working as expected...
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 :

xml file is:

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.
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 .
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.
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.
This should compile correctly with emscripten SDK 1.29.0 see #4.
same result if i use xmllint module:

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.

If you can put together a small repo that reproduces the issue I will look into this further.
https://github.com/rajashekhargundeti/xmllint-test
clone this repository and run server.js file
It is terminating the node process after validation.
I tested this with http module. same issue.

contents of test file:

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.
@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.
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
http://syssgx.github.io/xml.js/js/xmllint.js was compiled with an earlier version of emscripten perhaps there have been internal changes.
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.
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
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?
You can use my fork https://github.com/Beat-YT/xml.js