@@ -629,6 +629,35 @@ class XMLTestJVM {
629629 // does not work: roundtripNodes("<a/> <!-- epilogue -->")
630630 }
631631
632+ // using non-namespace-aware parser, this always worked;
633+ // using namespace-aware parser, this works with FactoryAdapter enhanced to handle startPrefixMapping() events;
634+ // see https://github.com/scala/scala-xml/issues/506
635+ def roundtrip (namespaceAware : Boolean , xml : String ): Unit = {
636+ val parserFactory : javax.xml.parsers.SAXParserFactory = javax.xml.parsers.SAXParserFactory .newInstance()
637+ parserFactory.setFeature(" http://javax.xml.XMLConstants/feature/secure-processing" , true )
638+ parserFactory.setFeature(" http://apache.org/xml/features/nonvalidating/load-external-dtd" , false )
639+ parserFactory.setFeature(" http://apache.org/xml/features/disallow-doctype-decl" , true )
640+ parserFactory.setFeature(" http://xml.org/sax/features/external-parameter-entities" , false )
641+ parserFactory.setFeature(" http://xml.org/sax/features/external-general-entities" , false )
642+ parserFactory.setFeature(" http://xml.org/sax/features/resolve-dtd-uris" , false )
643+ parserFactory.setNamespaceAware(namespaceAware)
644+ parserFactory.setXIncludeAware(namespaceAware)
645+
646+ assertEquals(xml, XML .withSAXParser(parserFactory.newSAXParser()).loadString(xml).toString())
647+ }
648+
649+ @ UnitTest
650+ def namespaceUnaware : Unit =
651+ roundtrip(namespaceAware = false , """ <book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"/>""" )
652+
653+ @ UnitTest
654+ def namespaceAware : Unit =
655+ roundtrip(namespaceAware = true , """ <book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"/>""" )
656+
657+ @ UnitTest
658+ def namespaceAware2 : Unit =
659+ roundtrip(namespaceAware = true , """ <book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"><svg xmlns:svg="http://www.w3.org/2000/svg"/></book>""" )
660+
632661 @ UnitTest
633662 def nodeSeqNs : Unit = {
634663 val x = {
0 commit comments