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.58k stars 309 forks source link

Ability to read & write DOCTYPE information #639

Open emmercm opened 9 months ago

emmercm commented 9 months ago

Description

Apologies if I missed this in the documentation, but I couldn't find it anywhere, even when stepping through the code.

I would like to read and write DOCTYPEs, including their public ID and system ID. xml2js has the ability to at least write them with the syntax:

xml2js.Builder({
  doctype: {
    pubID: '-//Logiqx//DTD ROM Management Datafile//EN',
    sysID: 'http://www.logiqx.com/Dats/datafile.dtd',
});

Input

Here's some example XML from No-Intro:

<?xml version="1.0"?>
<!DOCTYPE datafile PUBLIC "-//Logiqx//DTD ROM Management Datafile//EN" "http://www.logiqx.com/Dats/datafile.dtd">
<datafile>
    <header>
        <name>Nintendo - Game Boy (Parent-Clone)</name>
        <description>Nintendo - Game Boy (Parent-Clone)</description>
        <version>20230729-000034</version>
        <date>20230729-000034</date>
        <author>aci68, akubi, Arctic Circle System, Aringon, baldjared, Bent, BigFred, BitLooter, buckwheat, C. V. Reynolds, chillerecke, darthcloud, DeadSkullzJr, Densetsu, DeriLoko3, ElBarto, foxe, fuzzball, Gefflon, Hiccup, hking0036, InternalLoss, Jack, jimmsu, Just001Kim, kazumi213, leekindo, Lesserkuma, Madeline, NESBrew12, NGEfreak, nnssxx, norkmetnoil577, NovaAurora, omonim2007, Powerpuff, PPLToast, Psychofox11, rarenight, relax, RetroUprising, rpg2813, sCZther, SonGoku, Tauwasser, togemet2, UnlockerPT, xNo, xprism, xuom2</author>
        <url>https://www.no-intro.org</url>
    </header>
    <game name="[BIOS] Nintendo Game Boy Boot ROM (World) (Rev 1)">
        <description>[BIOS] Nintendo Game Boy Boot ROM (World) (Rev 1)</description>
        <release name="[BIOS] Nintendo Game Boy Boot ROM (World) (Rev 1)" region="EUR"/>
        <release name="[BIOS] Nintendo Game Boy Boot ROM (World) (Rev 1)" region="JPN"/>
        <release name="[BIOS] Nintendo Game Boy Boot ROM (World) (Rev 1)" region="USA"/>
        <rom name="[BIOS] Nintendo Game Boy Boot ROM (World) (Rev 1).gb" size="256" crc="59c8598e" md5="32fbbd84168d3482956eb3c5051637f5" sha1="4ed31ec6b0b175bb109c0eb5fd3d193da823339f" status="verified"/>
    </game>
    <game name="[BIOS] Nintendo Game Boy Boot ROM (Japan) (En)" cloneof="[BIOS] Nintendo Game Boy Boot ROM (World) (Rev 1)">
        <description>[BIOS] Nintendo Game Boy Boot ROM (Japan) (En)</description>
        <rom name="[BIOS] Nintendo Game Boy Boot ROM (Japan) (En).gb" size="256" crc="c2f5cc97" md5="a8f84a0ac44da5d3f0ee19f9cea80a8c" sha1="8bd501e31921e9601788316dbd3ce9833a97bcbc" status="verified"/>
    </game>
</datafile>

Code

new XMLParser({
  attributeNamePrefix: '',
}).parse(xmlContents);

Output

See the above

expected data

See the above

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 9 months 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 9 months ago

Honestly speaking, I have never thought about it. But it can be considered for future release.