- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
XML.write doesn't output anything
Sat, 2010-07-17, 18:05
hi,
i need to use XML.write (as my interface uses an OutputStream and not a File i cannot use XML.save), but i only get empty results:
$ scala
Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import java.io._; import xml._
import java.io._
import xml._
scala> val os = new FileOutputStream( new File( "/tmp/test.xml" ))
os: java.io.FileOutputStream = java.io.FileOutputStream@132a4df
scala> val node =
node: scala.xml.Elem =
scala> val w = new OutputStreamWriter( os )
w: java.io.OutputStreamWriter = java.io.OutputStreamWriter@169674
scala> XML.write( w, node, "UTF-8", true, null )
scala> os.close
scala> :quit
$ ls -la /tmp/test.xml
-rw-r--r-- 1 rutz wheel 0 17 Jul 18:03 /tmp/test.xml
what's going on there?
thanks for help!
best, -sciss-
Sat, 2010-07-17, 18:27
#2
Re: XML.write doesn't output anything
On Saturday July 17 2010, Sciss wrote:
> ...
>
> $ scala
> Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM,
> Java 1.6.0_20). Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala> import java.io._; import xml._
> import java.io._
> import xml._
>
> scala> val os = new FileOutputStream( new File( "/tmp/test.xml" ))
> os: java.io.FileOutputStream = java.io.FileOutputStream@132a4df
>
> scala> val node =
> node: scala.xml.Elem =
>
> scala> val w = new OutputStreamWriter( os )
> w: java.io.OutputStreamWriter = java.io.OutputStreamWriter@169674
>
> scala> XML.write( w, node, "UTF-8", true, null )
>
> scala> os.close
>
> scala> :quit
> $ ls -la /tmp/test.xml
> -rw-r--r-- 1 rutz wheel 0 17 Jul 18:03 /tmp/test.xml
>
>
> what's going on there?
You're writing to "w" but closing "os", which is downstream from w. If
you close w instead, it writes the XML to the file.
> thanks for help!
>
> best, -sciss-
Randall Schulz
sorry, forget about it. i need to add
w.flush
after XML.write...
best, -sciss-
Am 17.07.2010 um 18:05 schrieb Sciss:
> hi,
>
> i need to use XML.write (as my interface uses an OutputStream and not a File i cannot use XML.save), but i only get empty results:
>
> $ scala
> Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_20).
> Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala> import java.io._; import xml._
> import java.io._
> import xml._
>
> scala> val os = new FileOutputStream( new File( "/tmp/test.xml" ))
> os: java.io.FileOutputStream = java.io.FileOutputStream@132a4df
>
> scala> val node =
> node: scala.xml.Elem =
>
> scala> val w = new OutputStreamWriter( os )
> w: java.io.OutputStreamWriter = java.io.OutputStreamWriter@169674
>
> scala> XML.write( w, node, "UTF-8", true, null )
>
> scala> os.close
>
> scala> :quit
> $ ls -la /tmp/test.xml
> -rw-r--r-- 1 rutz wheel 0 17 Jul 18:03 /tmp/test.xml
>
>
> what's going on there?
>
> thanks for help!
>
> best, -sciss-
>