Warning: Trying to access array offset on value of type bool in /home/www/blog/wp-content/themes/catch-box/functions.php on line 1079

Caching XML access in Scala (example)

I want to create a hashed map for fast access to specific XML tags and attributes.

I used a config xml file of JDBCluster and its attribute name of the tag property. At the end of execution ht contains the following:

Map(Car -> List(longitude, latitude), Car2 -> List(longitude2, latitude2))

Here is the code:

object XmlTest extends Application {
  val testXML =
      <dao id="Car" class="dao.Car">
        <property name="longitude">
        <property name="latitude">
      <dao id="Car2" class="dao.Car2">
        <property name="longitude2">
        <property name="latitude2">

  val ht = new HashMap[String, Seq[String]]

  val l = for (dao <- testXML \ "daotype" \ "dao") yield
    (dao \ "@id" text, for (p <- dao \ "property") yield

  l.foreach (x => ht.put(x._1, x._2))