Noob question

52 views
Skip to first unread message

Lucius Meredith

unread,
Jan 23, 2013, 2:39:25 PM1/23/13
to scale...@googlegroups.com
Dear ScalesXMLers,

Is there a functional equivalent to the scala xml XML.loadString? This will return an element, rather than a doc. 

i did search through the scaladoc in ScalesXML, but didn't quite see what i was looking for.

Best wishes,

--greg

Chris Twiner

unread,
Jan 23, 2013, 5:48:57 PM1/23/13
to scale...@googlegroups.com
Hi Greg,

http://scala-scales.googlecode.com/svn/sites/scales/scales-xml_2.9.2/0.4.4/FullParsing.html
shows how to load:

val doc = loadXml(new FileReader("document.xml"))

The parameter to loadXml (and the related functions) can take any
InputStream or Reader. So a java.io.StringReader can be used as well.
The resulting doc provides full access to the prolog and end misc
items around the root element.

Let me know if that wasn't what you were after.

Cheers,
Chris

Lucius Meredith

unread,
Jan 23, 2013, 8:56:34 PM1/23/13
to scale...@googlegroups.com
Dear Chris,

Thanks for the quick reply! My mileage seems to vary:

Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import scales.xml._
import scales.xml._
import scales.xml._

scala> new java.io.StringReader( "<myElement>1</myElement>" )
new java.io.StringReader( "<myElement>1</myElement>" )
res0: java.io.StringReader = java.io.StringReader@1fd889aa

scala> loadXml( res0 )
loadXml( res0 )
<console>:12: error: type mismatch;
 found   : java.io.StringReader
 required: org.xml.sax.InputSource
Error occurred in an application involving default arguments.
              loadXml( res0 )
                       ^
java.io.StringReader <: org.xml.sax.InputSource?
  <notype> <: org.xml.sax.InputSource?
  false
false

scala> 

Any suggestions?

Best wishes,

--greg

Lucius Meredith

unread,
Jan 23, 2013, 9:02:43 PM1/23/13
to scale...@googlegroups.com
P.S. i checked out the source tree and did some spelunking through the tests and discovered i had incomplete imports. It's working now!
Reply all
Reply to author
Forward
0 new messages