dart-xml icon indicating copy to clipboard operation
dart-xml copied to clipboard

Support custom entities

Open vladchuk opened this issue 1 year ago • 1 comments

Currently, there is no way (or at least it's not clear how) to create a mapping of custom entities from the XML document. For example:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE appcast [ 
    <!ENTITY ver_1 "1.0.1">
    <!ENTITY ver_2 "1.0.2">
]>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
    <channel>
        <title>Test</title>
        <item>
            <enclosure
                sparkle:version="&ver_1;"
                url="http://localhost:8000/dev/test-install-&ver_1;.exe"
                sparkle:os="windows" />
        </item>
    </channel>
</rss>

Please add support for parsing doctype entities, so that they can be referenced within containing XML.

vladchuk avatar Nov 02 '23 18:11 vladchuk

You can define your own entity mapping:

const entityMapping = XmlDefaultEntityMapping({
    'joy': '😂',
    'tears': '😢',
});

final document = XmlDocument.parse('<xml>&joy; and &tears;</xml>',
    entityMapping: entityMapping);
print(document.rootElement.innerText);  // prints '😂 and 😢'

The doctype entities are already parsed to some extent, but mapping them automatically is non-trivial and requires a lot of work. Happy to take contributions in this area.

renggli avatar Nov 02 '23 19:11 renggli