Je cherche à créer un document comme celui-ci:Comment créer un noeud racine XML dans Scala sans un nom d'élément littéral?
<root/>
que je peux ajouter des enfants à programatically. En théorie, il ressemblerait à ceci:
val root_node_name = "root"
val doc = <{root_node_name}/>
Mais cela ne semble pas fonctionner:
error: not found: value <
Alors, ce que j'ai essayé à la place était le suivant:
val root_node_name = "root"
val doc = new scala.xml.Elem(null, root_node_name, null, scala.xml.TopScope, null)
qui compile mais à l'exécution, j'obtiens cette exception de pointeur nul:
java.lang.NullPointerException
at scala.xml.Utility$.toXML(Utility.scala:201)
at scala.xml.Utility$$anonfun$sequenceToXML$2.apply(Utility.scala:235)
at scala.xml.Utility$$anonfun$sequenceToXML$2.apply(Utility.scala:235)
at scala.Iterator$class.foreach(Iterator.scala:414)
at scala.runtime.BoxedArray$AnyIterator.foreach(BoxedArray.scala:45)
at scala.Iterable$class.foreach(Iterable...
J'utilise Scala 2.8. Des exemples de comment arracher ça? Merci.
Cela fonctionne avec l'avertissement de désapprobation maintenant. –
Avec l'API actuelle (Scala.xml 2.11.x): 'val doc = Elem.apply (null, nom_noeud_racine, scala.xml.Null, scala.xml.TopScope)' – Philippe