Я только изучаю scala и пытаюсь импортировать XML-файл на карту.XML содержит определения с использованием <word></word>
и <description></description>
.Когда я пытаюсь создать карту, я получаю сообщение об ошибке:
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>