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

Scala.js cannot load XML #198

Open
darkfrog26 opened this issue Mar 9, 2018 · 14 comments
Open

Scala.js cannot load XML #198

darkfrog26 opened this issue Mar 9, 2018 · 14 comments

Comments

@darkfrog26
Copy link

I'm attempting to parse XML from a String in Scala.js and I get this compile-time error:

[error] Referring to non-existent class javax.xml.parsers.SAXParserFactory$
[error]   called from scala.xml.factory.XMLLoader.parser()javax.xml.parsers.SAXParser
[error]   called from scala.xml.XML$.parser()javax.xml.parsers.SAXParser
[error]   called from scala.xml.factory.XMLLoader.loadString(java.lang.String)scala.xml.Node
[error]   called from scala.xml.XML$.loadString(java.lang.String)scala.xml.Node
darkfrog26 added a commit to outr/profig that referenced this issue Mar 9, 2018
@ashawley
Copy link
Member

The Java parser that the scala-xml library depends on isn't available from Scala.js at run time.

Note that if it's a literal string you're trying to parse, you should be able to use Scala's XML syntax to just declare your XML literal.

@SethTisue
Copy link
Member

SethTisue commented Mar 11, 2018

is this a feature an interested contributor could add...? (by substituting some JS thing for SAX?)

@darkfrog26
Copy link
Author

@ashawley and if it's not a String literal?

@SethTisue
Copy link
Member

@SethTisue
Copy link
Member

also relevant: #194, which suggests adding getting-started doc for Scala.js that would presumably cover this

@darkfrog26
Copy link
Author

I don't mind using scalaparse.Xml, but honestly have no idea how to actually use it in this context.

@ashawley
Copy link
Member

Perhaps, DOMParser could be used to handle XML strings in Javascript-land? We'd have to write a new "factory" to translate the Document to scala-xml objects.

@ashawley
Copy link
Member

Outside of scala.xml.factory.XMLLoader, the only other way to parse XML strings is the scala.xml.parsing.ConstructingParser. It's a little clunky, so I'm less than inclined to recommend it. It also has tiny bit of Java in it, so just enough to make Scala.js barf.

@hansdejong
Copy link

You might try this. (And be the first, I guess, it's tested once in scala.js):
https://github.com/hansdejong/xml-parser-scalajs

@eed3si9n
Copy link
Member

eed3si9n commented Aug 7, 2020

@SethTisue SethTisue changed the title Scala.js cannot load XML from String Scala.js cannot load XML Dec 7, 2020
@odenzo
Copy link

odenzo commented Apr 21, 2022

I am working on doing this, with scalajs-dom, but running into a few issues. Just thought I would mention it here, opening separate issues,

@armanbilge
Copy link
Contributor

armanbilge commented Apr 22, 2022

👍 I understand that @odenzo's solution uses scala-js-dom. This would work in browsers only (not Node.js), so IMO it would make most sense as a separate module within this repo. scala-js-dom is very nearly a stdlib for the Scala.js ecosystem, and I can vouch for its stability as a maintainer, so I think it would be an acceptable dependency to take on here.

Edit: btw, I'd be happy to review such a PR.

@phdoerfler
Copy link

@armanbilge
Copy link
Contributor

FYI fs2-data has just released an integration with scala-xml including a pure Scala, streaming XML parser. Therefore it is fully supported on JVM and JS!

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

8 participants