Scala: Find the DTD declaration in a file
Asked Answered
M

1

9

I'm not familiar with the scala XML library. Is there a simple way to find the DTD of a document ? From what I've seen so far, scala.xml.XML.load only returns the Elem (the XML content of the document) but not it's DTD. Is there another method to specifically do that?

Extra question: The same question for the XML declaration at the start of a document.

Minorite answered 13/5, 2011 at 8:18 Comment(0)
C
5

To get the full document, you'll want to use the ConstructingParser, like so:

val cpa = scala.xml.parsing.ConstructingParser.fromSource(src, false)
val doc = cpa.document()
val dtd = doc.dtd

The dtd is an instance of the DTD which should provide the information you're looking for.

As for the XML declaration, that's a ProcInstr. You'll want to look at the procInstr callback on the parser for how to get your hands on that.

Cowpuncher answered 13/5, 2011 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.