Parse multiple attributes with the same name
See original GitHub issueFirst 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:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@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.