I am using the HTML parser to parse an HTML string:
import nu.validator.htmlparser.{sax,common}
import sax.HtmlParser
import common.XmlViolationPolicy
val source = Source.fromString(response)
val html = new models.HTML5Parser
val htmlObject = html.loadXML(source)
How do I pull values for specific elements in the object? I can get the child and the label using this:
val child = htmlObject.child(1).label
But I don’t know how to get the content of the child. Also, I don’t know how to iterate through the child objects.
It’s unclear where your
HTML5Parserclass comes from, but I’m going to assume it’s the one in this example (or something similar). In that case yourhtmlObjectis just ascala.xml.Node. First for some setup:Now you can do the following, for example:
Etcetera.