NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.43k stars 297 forks source link

V3 to V4 migration guide? #623

Closed tylerblox closed 7 months ago

tylerblox commented 8 months ago

Description

### Input I'm wondering if there is any support for the methods from version 3 as I begin a migration to LTS version of fast-xml-parser I use `provider.getTraversalObj()` in my project to extract the children nodes, and metatdata from xml files. Is there a solution where I can continue to use getTraversalObject to get the intermediate object, or alternatively, is there a guide for migrating away from using it? Thank you in advance for the help/advice. ### Code ``` const XMLParser = require('fast-xml-parser'); xmlTraverser = XMLParser.getTraversalObj(fileData, FAST_XML_OPTIONS); const childNodes = Object.keys(xmlTraverser.child); const rootNode = childNodes[0]; ``` ### Output In V4, the getTraversalObj function has been removed [Bookmark](https://github.com/NaturalIntelligence/fast-xml-parser/stargazers) this repository for further updates. Visit [SoloThought](https://solothought.com) to know about recent features.
github-actions[bot] commented 8 months ago

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.

amitguptagwl commented 8 months ago

Hi @tylerblox , In version 4, there is a property to preserve the order of js properties. If it is set to true then you get intermediate object that you can use for traversal.

tylerblox commented 8 months ago

Hi @tylerblox , In version 4, there is a property to preserve the order of js properties. If it is set to true then you get intermediate object that you can use for traversal.

I'll try and play around with that a bit, adding that attribute to the config object didn't solve the problem by itself, but I'll see if I've missed something.

After checking on the XmlParser object created, there is no method on it called "getTraversalObject" even after adding the attribute preserveOrder

amitguptagwl commented 7 months ago

@tylerblox Sorry for the confusion what I meant to say is that "getTraversalObject" has been removed. Instead set preserve order to true to get intermediate object.

tylerblox commented 7 months ago

@tylerblox Sorry for the confusion what I meant to say is that "getTraversalObject" has been removed. Instead set preserve order to true to get intermediate object.

I see what you mean thank you, I also have a diff of the objects returned in both cases, so I am planning on making the migrations soon. I appreciate the responses greatly.