Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: add a method in DOMParser for parsing non-UTF8 XML documents #18

Closed
yan12125 opened this issue Jul 15, 2016 · 1 comment
Closed

Comments

@yan12125
Copy link

I'm not sure whether this is the correct place for requesting changes to the standard or not. If not please give me a direction.

The story starts from a rejected proposal at whatwg/fetch#16. With the new Fetch API, programmars need to parse XML streams by themselves. However, current DOMParser.parseFromString supports UTF-8 XML documents only. [1] The result is that there's no way to handle non-UTF8 XML documents correctly with Fetch API. I propose to add a new method that accepts typed arrays. Mozilla's private API DOMParser.parseFromBuffer looks promising. [2] With that I can do this:

fetch(xml_url).then(function (res) {
    res.arrayBuffer().then(function (buffer) {
        var parser = new DOMParser();
        var view = new Uint8Array(buffer);
        console.log(parser.parseFromBuffer(view, view.length, 'text/xml'));
    });
});

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1287071
[2] https://dxr.mozilla.org/mozilla-central/source/dom/webidl/DOMParser.webidl

@yan12125
Copy link
Author

Never mind. Just found TextDecoder that can handle non-UTF8 data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant