Custom Search
|
Re: Extracting attributes from XML...
Date: December 28, 2006
In-reply-to:
<45940F56.7000105@xxxxxxxxxxxxxx> On 12/28/06, Andy Dwelly <andy.dwelly@xxxxxxxxxxxxxx> wrote: I have some xml: beware that you might end up with several children of node "marius"... I noticed that the "preserve whitespace = false" option of the constructingparser seems to be buggy, so I use preserve whitespace = true. ...and I have some a method in an object to process it: the following all work, but require that you have an import xml.NodeSeq in scope. The last option will assign the empty string if there is no attribute "title", whereas the first three will all blow up with an exception. Here, the text method return something quite close to the XPath text() function. node match { case n @ Elem(_, "marius", attributes, _, _) => //val z:String = attributes.get("title") match { // case Some(v) => v.text //} //val z:String = attributes.get("title").get.text //val z:String = attributes("title").text val z:String = (node \ "@title").text Console.println(z) } supplementary question is should I really be starting from doc.docElem yes, that's the right node. since the xml spec permits procinstrs and comments before the actual node. hope this helps, Burak -- Burak Emir Research Assistant / PhD Candidate Programming Methods Group EPFL, 1015 Lausanne, Switzerland http://lamp.epfl.ch/~emir |