I am writing a small Scala application that does the following:
1) Reading XML / XHTML files
2) Do a little preprocessing
3) If necessary, change it using the XSLT stylesheet.
4) Process it a little.
5) Save it as XHTML.
My XML files will start with something like:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="../xslt/default.xslt"?>
If I read them with
scala.xml.XML.load(scala.xml.Source.fromFile(file))
I get Elem, but I'm losing XML processing instructions. I resorted to reading it as a String, doing String manipulations to find the xml stylesheet, and then passed it to
scala.xml.XML.load(scala.xml.Source.fromString(text))
There must be a better way to do this. I need to know which stylesheet I should use inside Scala , because Scala should call the XSLT processor if necessary.
Also, after I finished processing them, I save them with
scala.xml.Utility.trim(transformed).buildString(true)
but the resulting document does not contain XML declarations as well as HTML DOCTYPE. I also want to have them.
I know that these are technically two questions, but these are basically both ends of the same problem, and I suspect that the solution to the second problem is related to the solution to the first.