Skip to content
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

Not getting attribute value using XMLBuilder.build function #651

Closed
5 of 6 tasks
Faizan2030 opened this issue Apr 19, 2024 · 7 comments
Closed
5 of 6 tasks

Not getting attribute value using XMLBuilder.build function #651

Faizan2030 opened this issue Apr 19, 2024 · 7 comments
Labels
Pending Pending to be confirmed by user/author for some check/update/implementation

Comments

@Faizan2030
Copy link

Faizan2030 commented Apr 19, 2024

  • Are you running the latest version? Using 4.3.6
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool? Not working for me,

Description

I need to include xml attribute, like this : <internal-name tokenized="true">test test &gt; 14</internal-name>

Input

Code

defaultXmlOptions: {
      ignoreAttributes: false,
      attributeNamePrefix: "@_",
      indentBy: "  ",
      textNodeName: "#text",
      format: true,
  },
var testJson = { component: {
      "internal-name": {
          "#text": "test test > 14",
          "@_tokenized": true
      }
  }}

Here is the code that converts:

var parser = new XMLBuilder(CRUDService.defaultXmlOptions);
var xml = parser.build(testJson);

That attribute should have ="true"

Output

<component>
  <internal-name tokenized>test test &gt; 14</internal-name>
</component>

expected data

<component>
  <internal-name tokenized="true">test test &gt; 14</internal-name>
</component>

Would you like to work on this issue?

  • Yes
  • No

I posted the question here as well https://stackoverflow.com/questions/78354831/how-to-include-attribute-value-while-building-xml-using-fast-xml-parser

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.

@amitguptagwl
Copy link
Member

Can you please share the intermediate json object?

@Faizan2030
Copy link
Author

defaultXmlOptions: {
      ignoreAttributes: false,
      attributeNamePrefix: "@_",
      indentBy: "  ",
      textNodeName: "#text",
      format: true,
  },
var testJson = { component: {
      "internal-name": {
          "#text": "test test > 14",
          "@_tokenized": true
      }
  }}

@amitguptagwl
Copy link
Member

got your problem. "@_tokenized": true this is set as boolean. Can you try to set it as string?

@MarcoPolo-PasTonMolo
Copy link

Just tried this setting it as a string changes nothing. What you can do however is to add this property to your options and the original should work
suppressBooleanAttributes: false

@MarcoPolo-PasTonMolo
Copy link

Also see #611

@amitguptagwl amitguptagwl added the Pending Pending to be confirmed by user/author for some check/update/implementation label May 6, 2024
@amitguptagwl
Copy link
Member

closing the issue. feel free to reopen if still exist. Please also check for v5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending Pending to be confirmed by user/author for some check/update/implementation
Projects
None yet
Development

No branches or pull requests

3 participants