2
私は地図にXMLファイルをインポートしようとしているのですが、scalaとimを学んでいます。 XMLは、<word></word>
と<description></description>
を使用して定義を保持します。地図を作成しようとすると、エラーが表示されます。Scala XMLを地図にインポートする
Value update is not member of scala.collection.immutable.Map[String, String]
何か指摘したいと思います!
package main
import scala.xml._
object main {
def main(args: Array[String]): Unit = {
val definitions = XML.load("src\\main\\Definitions.xml");
val definitionMap = (Map[String, String]() /: (definitions \ "word")) { (map , defNode) =>
val word = (defNode \ "word").text.toString()
val description = (defNode \ "description").text.toString()
map(word) = description
}
println(definitions.getClass())
println("Number of elements is " + (definitions \\ "word").size)
}
}
とXMLのようなフォーマットされます。
<?xml version="1.0"?>
<definitions>
<entry>
<word>Ontology</word>
<description>A set of representational primitives with which to model a domain of knowledge or discourse.</description>
</entry>
<entry>
<word>Diagnostic</word>
<description>The process of locating problems with software, hardware, or any combination thereof in a system, or a network of systems.</description>
</entry>
<entry>
<word>Malware</word>
<description>Software that is intended to damage or disable computers and computer systems.</description>
</entry>
<entry>
<word>Capacitor</word>
<description>A device used to store an electric charge, consisting of one or more pairs of conductors separated by an insulator.</description>
</entry>
<entry>
<word>Stress Test</word>
<description>A test measuring how a system functions when subjected to controlled amounts of stress.</description>
</entry>
<entry>
<word>Registry</word>
<description>A hierarchical database that stores configuration settings and options on Microsoft Windows operating systems.</description>
</entry>
<entry>
<word>Antivirus</word>
<description>Designed to detect and remove computer viruses.</description>
</entry>
</definitions>
パーフェクト!ありがとうございました。それは理にかなっている :) – meriley