Scala - XML ​​PrettyPrinter.format () giving noSuchMethodError

I have this piece of code that is supposed to convert an XML.Elem object to readable and properly typed text, but when I run it, it keeps giving me an error and I can't figure out why as far as I know and searched I am using PrettyPrinter class as expected.

val xml = createXML(production_list: ProductionList)

// Using the PrettyPrinter class to make sure the XML is "human readable."  
val prettyPrinter = new scala.xml.PrettyPrinter(80, 2)
val prettyXml = prettyPrinter.format(xml)

XML.save(filename, scala.xml.XML.loadString(prettyXml), "UTF-8", true, null)

      

Here is the header of the createXML method:

def createXML(production_list: ProductionList): xml.Elem = {(...)}

      

And here's the error:

java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
  at scala.xml.NamespaceBinding.fromPrefixList$1(NamespaceBinding.scala:48)
  at scala.xml.NamespaceBinding.shadowRedefined(NamespaceBinding.scala:53)
  at scala.xml.NamespaceBinding.buildString(NamespaceBinding.scala:71)
  at scala.xml.Utility$.serialize(Utility.scala:218)
  at scala.xml.PrettyPrinter.traverse(PrettyPrinter.scala:151)
  at scala.xml.PrettyPrinter.format(PrettyPrinter.scala:209)
  at scala.xml.PrettyPrinter$$anonfun$format$2.apply(PrettyPrinter.scala:244)
  at scala.xml.PrettyPrinter$$anonfun$format$2.apply(PrettyPrinter.scala:244)
  at scala.xml.Utility$.sbToString(Utility.scala:33)
  at scala.xml.PrettyPrinter.format(PrettyPrinter.scala:244)
  ...

      

Snippet of my generated XML:

<?xml version='1.0' encoding='UTF-8'?>
<Schedule xsi:schemaLocation="http://www.dei.isep.ipp.pt/ip_2017 ip_2017_out.xsd " xmlns="http://www.dei.isep.ipp.pt/ip_2017" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <TaskSchedule order="ORD_1" productNumber="1" task="TSK_1" start="0" end="100">
                <PhysicalResources>
              <Physical id="PRS_1"/><Physical id="PRS_3"/><Physical id="PRS_4"/>
                </PhysicalResources>
                <HumanResources>
              <Human name="Antonio"/><Human name="Susana"/><Human name="Maria"/>
                </HumanResources>
            </TaskSchedule><TaskSchedule order="ORD_1" productNumber="1" task="TSK_3" start="100" end="260">
                <PhysicalResources>
              <Physical id="PRS_1"/><Physical id="PRS_4"/><Physical id="PRS_7"/>
                </PhysicalResources>
                <HumanResources>
              <Human name="Antonio"/><Human name="Maria"/><Human name="Manuel"/>
                </HumanResources>
            </TaskSchedule>
    </Schedule>

      

+3


source to share


1 answer


This can be fixed by changing some of the XML.save parameters. Take it:

XML.save(xmlPath, XML.loadString(printer.format(prettyXml, scala.xml.TopScope)) , "UTF-8", true, null)

      



World. RIP ISEP.

+2


source







All Articles