1
votes

I have an SVG document and the SVG style element has the attribute xml:space="preserve".

When trying to parse this document using Scala, an exception is thrown with the stack trace Exception in thread "main" org.xml.sax.SAXParseException: Namespace xml undefined at com.dautelle.xml.sax.RealtimeParser.parseError(Unknown Source) at com.dautelle.xml.sax.RealtimeParser.processAttribute(Unknown Source) at com.dautelle.xml.sax.RealtimeParser.parseContent(Unknown Source) at com.dautelle.xml.sax.RealtimeParser.parse(Unknown Source) at com.dautelle.xml.sax.XMLReaderImpl.parse(Unknown Source) at javax.xml.parsers.SAXParser.parse(SAXParser.java:395) at scala.xml.factory.XMLLoader$class.loadXML(XMLLoader.scala:40) at scala.xml.XML$.loadXML(XML.scala:40) at scalaapplication11.Main$.main(Main.scala:144) at scalaapplication11.Main.main(Main.scala) Java Result: 1

Here's the top of the SVG element <svg xmlns="http://www.w3.org/2000/svg" xmlns:jdipNS="http://jdip.sourceforge.org/jdipNS" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="optimizeQuality" contentScriptType="text/ecmascript" contentStyleType="text/css" height="680px" preserveAspectRatio="xMinYMin" version="1.0" viewBox="0 0 1835 1360" width="918px" zoomAndPan="magnify">

and here's the style element <style type="text/css" xml:space="preserve"><![CDATA[

    /* text */
    .titletext  {text-anchor:middle;stroke-width:0.3;font-family:sansserif;font-size:12;stroke:black;fill:black;}
    .provtext   {text-anchor:middle;stroke-width:0.3;font-family:sansserif;font-size:12;stroke:black;fill:black;}
    .labeltext  {stroke-width:0.1;stroke:black;fill:black;}
    .unordered           {fill:red; stroke:black; stroke-width:1;fill-opacity:0.90;}
    .labeltext

and I was able to use Java's DocumentBuilderFactory to append the xmlns:jdipNS attribute to the root of the document. But xmlns:xml doesn't get appended (likely because it's a standard namespace). I'm at a loss how to get Scala to handle the xml namespace.

1

1 Answers

2
votes

On the face of it this looks like a serious bug in the dautelle (Javolution?) XML parser. I don't know the Scala environment well, but it seems the parser has been allocated using the standard Java DocumentBuilderFactory so you should be able to switch to a different XML parser simply by changing your class path.