question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parse multiple attributes with the same name

See original GitHub issue

First of all, excellent package.

I’d like to request a feature for parsing a tag with several attributes that share the same name. I don’t think it’s valid XML, but it’s a real use case and I need to parse this… Currently, the package returns only the last attribute value. It would be great if it returned an array with the values, in the order they appear.

For example:

const xml = '<p foo="bar" foo="baz"></p>';

var fastXmlParser = require("fast-xml-parser");
var parsedXml = fastXmlParser.parse(xml, {
    ignoreAttributes: false
});

console.log(parsedXml);

This returns an object containing @_foo with value "baz". It would be awesome if it returned ["bar", "baz"] and simply "bar" if only the first attribute is present.

Hope to get some help. Thank You!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
amitguptagwlcommented, Sep 26, 2018

ok. So I’m assuming that API owner can’t modify their API. I may guide you to form this repo and do necessary changes. However, it’ll be an overhead to maintain the separate repo and merging any future change.

1reaction
amitguptagwlcommented, Sep 26, 2018

@hdodov Having any feature means compromising with performance. Though I don’t think it’ll be much impacting after having this feature. But I was wondering if we should implement the features for individual cases.

For instance, in your case, you can modify the XMLs (I’m assuming they’ve already generated) using regex. The only reason I’m avoiding the code change as this is one time required feature. You’ll not even need this feature once all the generated XMLs are processed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Multiple Attributes of same name - JAXB - Stack Overflow
The best workaround is to redefine the attribute as element. Otherwise when you need to read the attribute, you'll need to parse it...
Read more >
Processing XML in Python — ElementTree | by Deepesh Nair
Learn how you can parse, explore, modify and populate XML files with the Python ... Attributes are name–value pair that exist within a...
Read more >
XML Attributes - W3Schools
Attributes are designed to contain data related to a specific element. ... The following three XML documents contain exactly the same information:.
Read more >
How to work XPath multiple attributes? - eduCBA
Name of the attribute is defining the attribute name which we are using in multiple attributes, we can use multiple attributes in a...
Read more >
How to Parse an XML with Multiple Nodes and Attributes
Here pulling the text for elements only if they have one and attributes if at least the node has one. SELECT [Name] =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found