Hi ,
    I worked on it a bit more and found that the problem is not with writing
but with reading the xml file. While reading the xml file the apostrophe is
converted to some illegal character..The xml file being read is a Word
document saved as xml usng word2003. Tried using inputsource to resolve the
problem but without any success. Here is the code I used:
                 org.dom4j.io.SAXReader xmlReader = new SAXReader(); //
Using a SAX parsing reader.
        
xmlReader.setXMLReaderClassName("org.apache.xerces.parsers.SAXParser");

                 InputSource source = new InputSource(new
FileReader(wmlFile));
                 source.setEncoding("UTF-8");
                 this.docWML = xmlReader.read(source);
                 System.out.println(docWML.asXML());
I will appreciate if someone could help me with this.
Thanks,
Bejoy Nair

-----Original Message-----
From: Nair, Bejoy 
Sent: Monday, November 24, 2003 11:55 AM
To: '[EMAIL PROTECTED]'
Subject: RE: [dom4j-user] Re: How do I get the encoding in a document?

Hi,
   I tried doing the same but still got the illegal characters. 

        FileOutputStream out = new FileOutputStream("Document.xml");
        OutputFormat format = OutputFormat.createPrettyPrint(); 
        format.setEncoding("UTF-8");
        XMLWriter xmlWriter = new XMLWriter(out, format);
        xmlWriter.write(docXML);        
In the generated xml file, all the apostrophies(') are not readable....Any
clues?
bejoy

-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 24, 2003 9:39 AM
To: [EMAIL PROTECTED]; Klaus Engelhardt
Subject: [dom4j-user] Re: How do I get the encoding in a document?

The trick is to use the XMLWriter and use an OutputFormat object to set 
the encoding.

OutputFormat format = new OutputFormat();
format.setEncoding(...)
XMLWriter writer = new XMLWriter(format, new FileWriter("foo.xml"));
writer.write(someDoc);


On 24 Nov 2003, at 13:24, Klaus Engelhardt wrote:

> Dear James Strachan,
>
> I am unable to figure out how to get the original encoding of an XML
> document using Dom4j. I have seen email comments, etc. stating that
> this is impossible. My question is: is this true? and if so, why?
>
> The reason I need this is that some documents are in ISO-8859-1
> and others are in UTF-8. If I read in ISO-8859-1 with German
> special characters and write it back again as UTF-8, then the resulting
> document is no longer viewable with a simple ASCII text editor, at
> least as far as the special characters are concerned. So I really do
> need to get the original encoding in order to rewrite the modified
> document correctly.
>
> If I have to, I will pre-read the XML document to get the encoding
> by hand. But I would really love to spare this hopefully unnecessary
> effort!
>
> If you could send me a comment on this problem or better yet, a 
> solution,
> I would be very happy!
>
> Thanks,
> Klaus Engelhardt
>
>
>
> Klaus Engelhardt
> Metzstr. 8
> 81667 München
> Tel. 0049/89/483491 (home)
> Tel. 0049/89/3299-1409 (work)
>
>

James
-------
http://radio.weblogs.com/0112098/



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to