Hello,
why I parse xml (or html) on frontned. If I compile module which import xmldomparser
# main.nim
from xmldomparser import loadXML
...
and compile it into javascript
nim js main.nim
I get this error
~/.nimble/pkgs/xmldomparser-0.1.0/xmldomparser.nim(145, 11) Error: undeclared identifier: 'newStringStream'
thanks
From streams.nim:
when not defined(js):
type
StringStream* = ref StringStreamObj
## A stream that encapsulates a string.
##
## **Note:** Not available for JS backend.
# (.......)
proc newStringStream*(s: string = ""): owned StringStream =
## Creates a new stream from the string `s`.
##
## **Note:** Not available for JS backend.
nim -v
Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-05-18
Copyright (c) 2006-2019 by Andreas Rumpf
active boot switches: -d:release
OK, xmldomparser use stream and streams are not available for JS backend.
htmlparser library too.
How I can parse xml on frontend in nim with compile js?
thanks
proc newDOMParser(): JsObject {.importcpp:"new DOMParser()", nodecl.}
proc fetchEPG(): void {.async.} =
var res = await fetchText("/epg.xml")
var parser = newDOMParser();
var xmlDoc = parser.parseFromString(res,"text/xml");
log xmlDoc
EPG = xmlDoc
Then you can do something like:
EPG.getElementsByTagName("programme")