Skip to content

XhtmlParser throws java.lang.NullPointerException with valid doctype #259

Closed
@mjuopperi

Description

@mjuopperi

Parsing the XML below with the code provided produces the following error. Adding a space before the closing > (<!DOCTYPE html >) makes it work. The doctype without the space is valid according to the HTML5 spec.

I'm fairly sure the issue is that the parser expects a space here.

file:/path/to/file.xml:2:15: whitespace expected<html xmlns="http://www.w3.org/1999/xhtml">              ^
file:/path/to/file.xml:2:15: document must contain exactly one element              ^
java.lang.NullPointerException
	at scala.xml.NodeSeq.toString(test.sc:151)
	at A$A7$.print$$$Worksheet$$$Array$$$(test.sc:38)
	at A$A7$.main(test.sc:27)
	at A$A7.main(test.sc)
	at #worksheet#.#worksheet#(test.sc)
import scala.io.Source
import scala.xml.parsing.XhtmlParser

XhtmlParser(Source.fromFile("/path/to/file.xml", "UTF-8"))
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
    </head>
    <body>
        <p>Content</p>
    </body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions