logo       


Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Reading UTF-16: Content is not allowed in prolog: msg#00089

Subject: Reading UTF-16: Content is not allowed in prolog
Hi
I've been trying to write and read back a UTF-16 encoded XML document, without success. I can seemingly write the document ok (see  WriteUTF16.java ) and Firefox can open it without complaining (except the fact it doesn't have any style information). When I try and read back the document (using ReadUTF16.java) I get the following exception; -
 
 [Fatal Error] output.xml:1:40: Content is not allowed in prolog.
Exception in thread "main" org.xml.sax.SAXParseException: Content is not allowed
 in prolog.
        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
        at ReadUTF16.main(ReadUTF16.java:47)
I'm not sure whether I'm missing something simple, doing something really stupid or even if it is a platform dependent thing (I'm using Windows XP and Windows 2000).
 
many thanks
 
david
 
 
 
------- ReadUTF16.java -------
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
import java.util.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
 

public class ReadUTF16
{
 public static void main ( String rags[] ) throws Exception
 {
  System.out.println("read: main()");
  File f = new File ( "output.xml");
  
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  Document doc = db.parse( f.toURI().toString() );
 
  // serialise to console using jaxp 
  
  TransformerFactory tf = TransformerFactory.newInstance();  
  Transformer t = tf.newTransformer();
  t.setOutputProperty ( OutputKeys.INDENT , "yes" ) ;  
  DOMSource ds = new DOMSource ( doc  );  
  StreamResult res = new StreamResult  ( System.out ) ;
  t.transform ( ds , res ) ;
    
 }// end method
}// end class
 
 
------- WriteUTF16.java -------

import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
import java.util.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
 

public class WriteUTF16
{

 public static void main ( String rags[] ) throws Exception
 {
  System.out.println("main()");
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  Document doc = db.newDocument();
  Element element = doc.createElement( "tagname") ;
  element.setAttribute("test","test-value");
  doc.appendChild ( element ) ;
  // serialise using jaxp 
   File f = new File ( "output.xml");
  TransformerFactory tf = TransformerFactory.newInstance();
  
  Transformer t = tf.newTransformer();
  
  Properties p = t.getOutputProperties();
  // print properties to console
  p.list ( System.out ) ;
  // set up the transformer
  // there are properties to set and error listeners which can be set
  
  // does something when output to the console anyway...
  t.setOutputProperty ( "encoding" , "UTF-16" ) ;
  // set indentation
  t.setOutputProperty ( OutputKeys.INDENT , "yes" ) ;
  // new DOMSource instance
  DOMSource ds = new DOMSource ( doc  );
  // Print Writer
  PrintWriter writer = new PrintWriter( new BufferedWriter ( new FileWriter ( f) ) );  
  StreamResult res = new StreamResult  ( writer ) ;
  // transform
  t.transform ( ds , res ) ;    
 }// end method
}// end class

Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe