0

I have been trying to parsing one xml file through npm package node-expat there certain xml file

<?xml version="1.0" encoding="utf-8"?><root><header><documentType>ItemFulfillment</documentType></header><record id="1"><Document_Number>IF0916382</Document_Number><Picked_Date>2022-05-06T16:45:04.543</Picked_Date><Reference_Number>IF0916382</Reference_Number><Item><Itemline><Item>GSW0145-GR02 : GSW0145-GR02-1/2</Item><OrderedQuantity>1.00000</OrderedQuantity><ShippedQuantity>1.00000</ShippedQuantity><UPC>019624238898</UPC></Itemline><Itemline><Item>GSW0144-GR02 : GSW0144-GR02-1/2</Item><OrderedQuantity>1.00000</OrderedQuantity><ShippedQuantity>1.00000</ShippedQuantity><UPC>019624272588</UPC></Itemline></Item><Packaging><PackageLine><Tracking_Number>1ZEW5167YW14791144</Tracking_Number><Weight>1.20000</Weight></PackageLine></Packaging><Shipping_Addressee>Katherine Hooks</Shipping_Addressee><Shipping_Address_1>815 Edwards Road</Shipping_Address_1><Shipping_Address_2>Unit 20</Shipping_Address_2><Shipping_City>Greenville</Shipping_City><Shipping_Country>US</Shipping_Country><Shipping_Zip>29615</Shipping_Zip><Shipping_State_Province>SC</Shipping_State_Province></record></root>

This files works in almost all cases but sometimes it fails.Getting following error Read failed for Details not well formed(invalid token)

1 Answers1

0

You can check below npm package for parsing XML.

https://www.npmjs.com/package/fast-xml-parser

If you want to use you same npm package then please check the below image for your reference.enter image description here

Piyusha Patel
  • 67
  • 1
  • 8
  • I can't change the package. – Akshay Vashishtha May 11 '22 at 08:43
  • Before parsing the XML, check whether is a valid XML string or not. Can you please share your code snippet in your questions? This will give a better understanding. – Piyusha Patel May 11 '22 at 10:39
  • The problem is that my xml file is correct as you see the input it throws an error but if you check with the validator you get no error found even most of the time it will parse it properly – Akshay Vashishtha May 13 '22 at 05:49
  • This is is file parsing error. If you want to confirm then go inside the node-module folder of node-expat and check the file path which I shared by image and that image I edited into my answers above – Piyusha Patel May 15 '22 at 05:51