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

Use XMLDocument type when parsing XML string in DOMParser #771

Open
andriygm opened this issue Apr 11, 2023 · 3 comments
Open

Use XMLDocument type when parsing XML string in DOMParser #771

andriygm opened this issue Apr 11, 2023 · 3 comments

Comments

@andriygm
Copy link

andriygm commented Apr 11, 2023

Currently, DOMParser's parseFromString method returns a Document type when using MIME type "text/xml". We should instead return an XMLDocument. It doesn't look like the XMLDocument type exists, so that should be created as well.

@andriygm andriygm changed the title Use XMLDocument type when parsing XML string in DOMParser Use XMLDocument type when parsing XML string in DOMParser May 12, 2023
@armanbilge
Copy link
Member

armanbilge commented Aug 9, 2023

Hmm, I just took a proper look at this and I'm not sure if we can make an improvement here.

We should definitely add XMLDocument, I'm about to open a PR that does that. Update: #804

However, it is difficult to refine the return type of parseFromString based on its arguments. This is a very common problem: for example document.createElement("div") is returning an HTMLDivElement but we are not reflecting that in the type. For the user, the solution is simply to do an asInstanceOf cast.

In the future if we dropped support for Scala 2 (or split sources across Scala 2/3) we could possibly do something interesting with literal types. That is tracked in this issue:

@andriygm
Copy link
Author

andriygm commented Aug 9, 2023

Is parseXMLFromString too unwieldy?

@armanbilge
Copy link
Member

parseXMLFromString is not a real method in the DOM APIs. We only facade the raw APIs (warts and all), and leave it up to other libraries to solve the usability issues.

For example see:
https://github.com/raquo/scala-dom-types#what-about-scala-js-dom

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

2 participants