Comments (4)
from fast-xml-parser.
Hi,
In this example:
<?xml version="1.0" encoding="UTF-8"?> <root xml:space="preserve"> <result toptype="Normal"> <line number="1"> 234 +</line> <line number="1"> 100 +</line> <line number="2"> Total: 334.00 </line> </result> </root>
This is the result:
{"root":{ "space":"preserve", "result":{ "toptype":"Normal", "line":[ { "number":"1", "text":"234 +" }, { "number":"1", "text":"100 +" }, { "number":"2", "text":"Total: 334.00 " } ] } } }
If I comment the line (in bold):
var getTraversalObj =function (xmlData,options){
options = buildOptions(options);
//xmlData = xmlData.replace(/>(\s+)/g, ">");//Remove spaces and make it single line.
var tags = getAllMatches(xmlData,tagsRegx);
var xmlObj = new xmlNode('!xml');
var currentNode = xmlObj;
I get the expected result:
"{"root":{ "space":"preserve", "result":{ "toptype":"Normal", "line":[ { "number":"1", "text":" 234 +" }, { "number":"1", "text":" 100 +" }, { "number":"2", "text":" Total: 334.00 " } ] } } }"
Other libs like xml2json use optional trim parameter:
var options = {
object: false,
reversible: false,
coerce: false,
sanitize: true,
trim: true,
arrayNotation: false
alternateTextNode: false
};
from fast-xml-parser.
Thanks. Now I got your point. I believe just commenting the line in the code , as you mentioned, may cause issue when XML is not well formatted. So I'll have to handle it.
Unfortunately I don't have any machine to work. So let's wait for the weekend so that I can borrow someone's machine and fix this.
from fast-xml-parser.
@hermosilla issue is solved. Your suggestion worked. Thanks
from fast-xml-parser.
Related Issues (20)
- Attribute in oneListGroup is not parsed correctly HOT 1
- All special characters are not correctly parsed HOT 4
- Ability to read & write DOCTYPE information HOT 2
- parser malfunctions when textNodeName is the same as a tag name HOT 8
- Node attributes get lost on XML parsing HOT 1
- Decimal point is not preserved after parsed to json. HOT 6
- Difficulty treating some numeric tags as string HOT 2
- XML parse looks good on Online tool, but when using API crashes HOT 2
- Any tag which has a format like <!D%s> where %s - any sequence of characters is perceived as <!DOCTYPE> and causes error HOT 2
- Not getting attribute value using XMLBuilder.build function HOT 7
- Object doesn't support property or method 'trimStart' HOT 3
- Parser erroneously adds `"@_/": true` attr for self-closing stop nodes HOT 2
- Missing `entities` option in XMLBuilder HOT 2
- XMLBuilder Incorrectly Serializes String "true" as Boolean Attribute HOT 3
- XMLParser - `tagValueProcessor` called only on leaf nodes HOT 5
- Configuration to explicitly disable number parsing for specific xml tag values HOT 3
- Foriegn characters are translated to what seems to be a Unicide Hex HOT 2
- attribute value with "true" string is not able to buid again with XMLBuilder HOT 6
- https://github.com/advisories/GHSA-mpg4-rc92-vx8v HOT 4
- Feature Request: option to ignore attributes by name (by array of string | regex) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast-xml-parser.