gpt4 book ai didi

xml - Scala - XML PrettyPrinter.format() 给出 noSuchMethodError

转载 作者:数据小太阳 更新时间:2023-10-29 02:33:34 27 4
gpt4 key购买 nike

我有这段代码应该将 XML.Elem 对象转换为可读且正确缩进的文本,但是当我运行它时它总是给我一个错误,我不明白为什么因为据我所知和搜索我正在按预期使用 PrettyPrinter 类。

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)

这是 createXML 方法的标题:

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

这里是错误:

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)
...

我创建的 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>

最佳答案

这可以通过更改 XML.save 的一些参数来解决。拿着它:

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

和平。安息吧。

关于xml - Scala - XML PrettyPrinter.format() 给出 noSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44418476/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com