You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{X2jOptionsOptional,XMLParser}from'fast-xml-parser';import{readFile,writeFile}from'fs/promises';constPATH=`${__dirname}/ControleAcionario.xml`;constignoreTags=[/ControlesAcionariosAcionistasFilhos/i,];/** * I have also tried with: * ArrayOfControleAcionarioAcionista.ControleAcionarioAcionista.ControlesAcionariosAcionistasFilhos */conststopNodes=['*.ControlesAcionariosAcionistasFilhos',];consttagValueProcessor=(tagName: string,tagValue: string,jPath: string)=>{if(ignoreTags.some((re)=>re.test(jPath)))return'';returntagValue;};constoptions: X2jOptionsOptional={
tagValueProcessor,trimValues: true,
stopNodes,};(async()=>{constparser=newXMLParser(options);constxml=(awaitreadFile(PATH)).toString();constjson=JSON.stringify(parser.parse(xml),null,2);awaitwriteFile(`${__dirname}/test.json`,json);})();
Output
.../node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js:299
if(!result) throw new Error(`Unexpected end of ${tagName}`);
^
Error: Unexpected end of ControlesAcionariosAcionistasFilhos
at OrderedObjParser.parseXml (.../node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js:299:31)
at XMLParser.parse (.../node_modules/fast-xml-parser/src/xmlparser/XMLParser.js:35:48)
at .../playground/xmlparse/xmlparse.ts:32:38
Description
The XMLParser fails when stopNode is an empty (self-closing) tag.
If I remove the problematic tag, everything works fine.
Input
Code
Output
expected data
Would you like to work on this issue?
Bookmark this repository for further updates.
The text was updated successfully, but these errors were encountered: