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.45k stars 296 forks source link

Read empty attributes #578

Open Peterculazh opened 1 year ago

Peterculazh commented 1 year ago

Description

I have xml which have empty attribute name. How I can read every attribute include empty attribute?

Input

<Tag xmlns="sql='urn:schemas-microsoft-com:xml-sql'"><Anotertag>
<MyTag test1='1' test2='2' test3='3' test4='4'  ='some value'/>
</Anotertag></Tag>

Code

const parser = new XMLParser({
  ignoreAttributes: false,
  attributeNamePrefix: '',
});
const file = fs.readFileSync(`downloads/${filename}`, 'utf-8');
const data = parser.parse(file);

Output

{
  Tag: {
    Anotertag: {
      MyTag: {
        test1: "1",
        test2: "2",
        test3: "3",
        test4: "4",
      },
    },
    xmlns: "sql='urn:schemas-microsoft-com:xml-sql'",
  },
}

expected data

{
  Tag: {
    Anotertag: {
      MyTag: {
        test1: "1",
        test2: "2",
        test3: "3",
        test4: "4",
        EMPTY_TAG1: "some value"
      },
    },
    xmlns: "sql='urn:schemas-microsoft-com:xml-sql'",
  },
}

Would you like to work on this issue?

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

github-actions[bot] commented 1 year 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 1 year ago

Honestly speaking, it is a very particular case and has very less use cases.