Coder Social home page Coder Social logo

Comments (4)

amitguptagwl avatar amitguptagwl commented on August 17, 2024

from fast-xml-parser.

hermosilla avatar hermosilla commented on August 17, 2024

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.

amitguptagwl avatar amitguptagwl commented on August 17, 2024

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.

amitguptagwl avatar amitguptagwl commented on August 17, 2024

@hermosilla issue is solved. Your suggestion worked. Thanks

from fast-xml-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.