fast-xml-parser icon indicating copy to clipboard operation
fast-xml-parser copied to clipboard

When using the for loop, there is an issue with parsing

Open coderi521 opened this issue 6 months ago • 2 comments

  • [x] Are you running the latest version?
  • [x] Have you included sample input, output, error, and expected output?
  • [ ] Have you checked if you are using correct configuration?
  • [ ] Did you try online tool?
  • [ ] Have you checked the docs for helpful APIs and examples?

Description

When using the for loop, there is an issue with parsing

Input

Code

const { XMLParser, XMLBuilder } = require('fast-xml-parser') const fs = require('fs') const _XMLParser = new XMLParser({ ignoreAttributes: false }) const _builder = new XMLBuilder({ ignoreAttributes: false, processEntities: false, format: true, }) /** *

  • @param {string} filePath
  • @returns jsonObj xmlObject / const xmlCodeToAST = filePath => { const fileContent = fs.readFileSync(filePath, 'utf8') return _XMLParser.parse(fileContent) } /*
  • @param {Object} xmlObj
  • @returns xmlString */ const astToXmlCode = xmlObj => { return _builder.build(xmlObj) }

const ast = xmlCodeToAST('./test.mpx') console.log(ast, 'ast') const xml = astToXmlCode(ast) console.log(xml, 'xml')

Output

{ script: { '': '', '#text': 'function test() {\n for (let i = 0; i' } } ast

xml

expected data

Would you like to work on this issue?

  • [ ] Yes
  • [ ] No

Bookmark this repository for further updates. Visit SoloThought to know about recent features.

coderi521 avatar Jul 09 '25 08:07 coderi521

We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.

github-actions[bot] avatar Jul 09 '25 08:07 github-actions[bot]

it seems you're trying to use the same instance. Try with a new instance, everytime and check if it works.

amitguptagwl avatar Jul 10 '25 03:07 amitguptagwl