summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-05-23 04:37:55 +0000
committerBurak Emir <emir@epfl.ch>2006-05-23 04:37:55 +0000
commiteec07f743193f9a7b34c0f89648a68a4cd7e72fc (patch)
tree00901f91ea4389d84b02a8297eb004c37f87ced8 /src
parent07724cb4b0872966041047d370e60bdfa97b55da (diff)
downloadscala-eec07f743193f9a7b34c0f89648a68a4cd7e72fc.tar.gz
scala-eec07f743193f9a7b34c0f89648a68a4cd7e72fc.tar.bz2
scala-eec07f743193f9a7b34c0f89648a68a4cd7e72fc.zip
added saveFull method
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/xml/XML.scala21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/library/scala/xml/XML.scala b/src/library/scala/xml/XML.scala
index 37e043afbc..b715c35c71 100644
--- a/src/library/scala/xml/XML.scala
+++ b/src/library/scala/xml/XML.scala
@@ -69,20 +69,33 @@ object XML {
final def loadString( string:String ): scala.xml.Elem =
load(new StringReader(string))
- /** saves XML to filename with encoding ISO-8859-1 */
- final def save( filename:String, doc:Elem ):Unit = {
+ /** saves XML to filename with encoding ISO-8859-1. Does not write an xml-decl or doctype. */
+ final def save(filename: String, doc: Elem): Unit =
+ save(filename, doc, "ISO-8859-1");
+
+ /** saves XML to filename with given encoding. Does not write an xml-decl or doctype. */
+ final def save(filename: String, doc: Elem, enc: String): Unit =
+ saveFull(filename, doc, enc, false, null);
+
+ final def saveFull(filename: String, doc: Document, xmlDecl: Boolean, doctype: dtd.DocType): Unit =
+ saveFull(filename, doc, "ISO-8859-1", xmlDecl, doctype);
+
+ final def saveFull(filename: String, doc: Document, enc: String, xmlDecl: Boolean, doctype: dtd.DocType): Unit = {
/* using NIO classes of JDK 1.4 */
import java.io.{FileOutputStream,Writer};
import java.nio.channels.{Channels,FileChannel};
val fos = new FileOutputStream( filename );
- val w:Writer = Channels.newWriter( fos.getChannel(), "ISO-8859-1" );
+ val w: Writer = Channels.newWriter( fos.getChannel(), enc );
/* 2do: optimize by giving writer parameter to toXML*/
- w.write( Utility.toXML( doc ));
+ if(xmlDecl) w.write( "<?xml version='1.0' encoding='"+enc+"'?>\n");
+ if(doctype!=null) w.write( doctype.toString()+"\n");
+ w.write( Utility.toXML( doc.docElem ));
w.close();
fos.close();
+
}
}