hgourvest / node-xml-lite Goto Github PK
View Code? Open in Web Editor NEWPure javascript XML SAX parser for Node.js
License: Mozilla Public License 2.0
Pure javascript XML SAX parser for Node.js
License: Mozilla Public License 2.0
For example, if I parse
<li>I've talked with a lot of <country>Cuba</country> people.</li>
it yields the following JSON
{ name: 'li',
childs: [
'I\'ve talked with a lot of ',
{ name: 'country', childs: ['Cuba'] },
'people.'
]
}
Notice how the space between "Cuba" and "people" is stripped out. Is this the intended behavior? Is there a workaround for this?
The parser is stripping \r\n characters from values that are not wrapped in CDATA tags.
Is there a particular reason for that?
Is this an intended feature ? if it is it should not be ! Completely defeats the point of CData
That would be great to implement a toString method, so that this code would return the string representation of the xml
var xmlParser = require('node-xml-lite');
var xmlData = '<div><b>hello</b><ul><li>world</li><li>hi</li></ul></div>';
parsedData = xmlParser.parseString(xmlData);
console.log(parsedData.toString(), xmlData);
The parser rejects this svg file because it expects attribute names to be alphanumeric, which stroke-width
is not.
There are many other characters which are allowed in an XML Name, listed in the spec (see: Names and Tokens) which don't seem to be supported...
If you have a comment like this
<!--comment-with-hyphen-->
the output string will be
commentithyphen
the '-' character and the character after it will be missing.
here is a simple code to demonstrate it
var xml = require('node-xml-lite');
var fs = require('fs');
function parseFunc (state, a, b) {
switch (state) {
case xml.xtComment:
console.log(a);
break;
}
return true;
}
fs.writeFile('bug.xml', '<!-- comment-with-hyphen -->', function(err, data) {
fs.readFile('bug.xml', 'utf8', function(err, data) {
// file output
console.log(data);
// parser output
xml.SAXParseFile('bug.xml', parseFunc);
});
});
// output
// <!-- comment-with-hyphen -->
// commentithyphen
xml file like this
<!-- Error -->
<?xml version="1.0" encoding="utf-8"?>
<!-- Error -->
<svg width="40" height="32" viewBox="0 0 40 32">
<!-- Works -->
<ellipse cx="20" cy="16" rx="20" ry="16"/>
</svg>
<!-- Works -->
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.