2
저는 스칼라와 메신저를 배우면서 XML 파일을지도로 가져 오려고합니다. XML은 <word></word>
및 <description></description>
을 사용하여 정의를 보유합니다. 지도를 만들려고 할 때 오류가 발생합니다.스칼라 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