Skip to content

Unexpected output for 5.2.0 #750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 of 7 tasks
izkizk8 opened this issue May 21, 2025 · 3 comments
Closed
6 of 7 tasks

Unexpected output for 5.2.0 #750

izkizk8 opened this issue May 21, 2025 · 3 comments

Comments

@izkizk8
Copy link

izkizk8 commented May 21, 2025

  • Are you running the latest version?
  • 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

The output of version 5.2.0 and version 4 is different, but I saw in the readme that the functions of version 5 and version 4 are the same
demo: https://stackblitz.com/edit/sb1-ize1zhzz?file=package.json

Input

{
"data": [
{
"lpepPickupDatetime": "2015-01-04T13:09:27Z",
"lpepDropoffDatetime": "2015-01-04T13:25:50Z",
"passengerCount": 2
},
{
"lpepPickupDatetime": "2015-01-05T10:00:00Z",
"lpepDropoffDatetime": "2015-01-05T10:15:00Z",
"passengerCount": 1
}
]
}

Code

    const builder = new XMLBuilder({ arrayNodeName: 'row', format: true });
    const res = builder.build({
        data: [
            {
                lpepPickupDatetime: '2015-01-04T13:09:27Z',
                lpepDropoffDatetime: '2015-01-04T13:25:50Z',
                passengerCount: 2
            },
            {
                lpepPickupDatetime: '2015-01-05T10:00:00Z',
                lpepDropoffDatetime: '2015-01-05T10:15:00Z',
                passengerCount: 1
            }
        ]
    });

Output

<data>
  <lpepPickupDatetime>2015-01-04T13:09:27Z</lpepPickupDatetime>
  <lpepDropoffDatetime>2015-01-04T13:25:50Z</lpepDropoffDatetime>
  <passengerCount>2</passengerCount>
</data>
<data>
  <lpepPickupDatetime>2015-01-05T10:00:00Z</lpepPickupDatetime>
  <lpepDropoffDatetime>2015-01-05T10:15:00Z</lpepDropoffDatetime>
  <passengerCount>1</passengerCount>
</data>

expected data

<data>
  <row>
    <lpepPickupDatetime>2015-01-04T13:09:27Z</lpepPickupDatetime>
    <lpepDropoffDatetime>2015-01-04T13:25:50Z</lpepDropoffDatetime>
    <passengerCount>2</passengerCount>
  </row>
</data>
<data>
  <row>
    <lpepPickupDatetime>2015-01-05T10:00:00Z</lpepPickupDatetime>
    <lpepDropoffDatetime>2015-01-05T10:15:00Z</lpepDropoffDatetime>
    <passengerCount>1</passengerCount>
  </row>
</data>

Would you like to work on this issue?

  • Yes
  • No

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

Copy link

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.

@izkizk8
Copy link
Author

izkizk8 commented May 21, 2025

Copilot gave me an reference but it was deleted:
https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v5/1.GettingStarted.md
Maybe this is a breaking change?

@amitguptagwl
Copy link
Member

arrayNodeName is used when root element is an array. In your case, property name data is present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants