eXist-1.0b2-build-1107 - XML corruption when retrieving XML documents

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

eXist-1.0b2-build-1107 - XML corruption when retrieving XML documents

Gareth Hall
 Hi, 
 
I am running eXist-1.0b2-build-1107. I am running the code below with Tomcat 5.5 and JRE 5.
 
I have a problem with documents appearing to be corrupted when retrieved using the following code: - 
 
           // get root-collection
            Collection col =
                DatabaseManager.getCollection(URI, username, password);
            // get query-service
            XPathQueryService service =
                (XPathQueryService) col.getService( "XPathQueryService", "1.0" );
           
            // set pretty-printing on
            service.setProperty(OutputKeys.INDENT, "yes" );
            service.setProperty(OutputKeys.ENCODING, encoding);
            
            // execute query and get results in ResourceSet
            ResourceSet result = service.query(query);
            
            for ( int i = 0; i < (int) result.getSize(); i++ ) {
 
                System.out.println((String)((XMLResource) result.getResource( (long) i)).getContent());  
            }
 
When retrieving the XML document (which can be viewed via the Java client with no problems): -
 
<ADMIN id="1126626525826" created="13/09/2005 at 04:48" type="normal">
    <NAME first="Gareth" family="Hall"/>
    <EMAIL>[hidden email]</EMAIL>
    <PASSWORD>f93fe2b182c016d7cb9b08981a3e26bc</PASSWORD>
</ADMIN>
 
using the above code I running within Tomcat 5.5 I get the following output: -
 
<ADMIN id="1126626525826" created="13/09/2005 at 04:48" t??T??????(?????9♣5¶????
???↔????????????!??????(???☻♥?T?¶???v↨&WF??▬??♠▬66V?GW&R?6????T?¶???☻☻☻♥?♦§55t?$
??X?♫♫N♀XL?L????♂?►T????☼??♂?Q‼RS??
 
Does anybody have any idea why I am receiving this result?

Thank you for your help.

Gareth

--
Gareth Hall
Mobile: +44 (0) 7971037081
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: eXist-1.0b2-build-1107 - XML corruption when retrieving XML documents

golgoth14@nonlimit.ch
Hi,

    I'think it's an encoding problem.
    The console where you print the result doesn't support the encoding you are using.

    Try to dump the result into a FileOutputStream and specify the right encoding.

    If you're using Eclipse, configure it with UTF-8 encoding or with the same encoding as your.


Stéphane

Gareth Hall wrote:
 Hi, 
 
I am running eXist-1.0b2-build-1107. I am running the code below with Tomcat 5.5 and JRE 5.
 
I have a problem with documents appearing to be corrupted when retrieved using the following code: - 
 
           // get root-collection
            Collection col =
                DatabaseManager.getCollection(URI, username, password);
            // get query-service
            XPathQueryService service =
                (XPathQueryService) col.getService( "XPathQueryService", "1.0" );
           
            // set pretty-printing on
            service.setProperty(OutputKeys.INDENT, "yes" );
            service.setProperty(OutputKeys.ENCODING, encoding);
            
            // execute query and get results in ResourceSet
            ResourceSet result = service.query(query);
            
            for ( int i = 0; i < (int) result.getSize(); i++ ) {
 
                System.out.println((String)((XMLResource) result.getResource( (long) i)).getContent());  
            }
 
When retrieving the XML document (which can be viewed via the Java client with no problems): -
 
<ADMIN id="1126626525826" created="13/09/2005 at 04:48" type="normal">
    <NAME first="Gareth" family="Hall"/>
    <EMAIL>[hidden email]</EMAIL>
    <PASSWORD>f93fe2b182c016d7cb9b08981a3e26bc</PASSWORD>
</ADMIN>
 
using the above code I running within Tomcat 5.5 I get the following output: -
 
<ADMIN id="1126626525826" created="13/09/2005 at 04:48" t??T??????(?????9♣5¶????
???↔????????????!??????(???☻♥?T?¶???v↨&WF??▬??♠▬66V?GW&R?6????T?¶???☻☻☻♥?♦§55t?$
??X?♫♫N♀XL?L????♂?►T????☼??♂?Q‼RS??
 
Does anybody have any idea why I am receiving this result?

Thank you for your help.

Gareth

--
Gareth Hall
Mobile: +44 (0) 7971037081

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: eXist-1.0b2-build-1107 - XML corruption when retrieving XML documents

Gareth Hall


Thank you for your time.
 
I am storing the document using UTF-8. Further to this when connecting to the database I am specifying that the encoding is UTF-8.
 
I've also tried this with ISO-8859-1.
 
When I use getBytes specifying the encoding - this just gives me more mixed up characters!
 
This is obviously something to do with the encoding and my code works fine with version 0.9 of eXist so I'm stumped!
 
Gareth
 


 
On 9/19/05, Golgoth 14 <[hidden email]> wrote:
Not in Tomcat, in your application.

Try this:
   String resultStr = (String)((XMLResource) result.getResource ( (long)
i)).getContent();
   String encodedResultStr = new String(resultStr.getBytes("UTF-8"));

   System.out.println(encodedResultStr);


   If it doesn't work, change the encoding "UTF-8" with your encoding.

Gareth Hall wrote:

> Encoding problem where? In Tomcat?
>
> The result is pulled out of the Tomcat logs.
>
> When I don't print this result I export to a file and experience the
> same problem.
>
> Thank you for your help.
> Gareth
>
>
> On 9/19/05, *Golgoth 14* <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi,
>

>         I'think it's an encoding problem.
>         The console where you print the result doesn't support the
>     encoding you are using.
>
>         Try to dump the result into a FileOutputStream and specify the
>     right encoding.
>
>         If you're using Eclipse, configure it with UTF-8 encoding or
>     with the same encoding as your.
>
>
>     Stéphane
>
>
>     Gareth Hall wrote:
>
>>      Hi,
>>
>>     I am running eXist-1.0b2-build-1107. I am running the code below
>>     with Tomcat 5.5 and JRE 5.
>>
>>     I have a problem with documents appearing to be corrupted
>>     when retrieved using the following code: -
>>
>>                // get root-collection
>>                 Collection col =
>>                     DatabaseManager.getCollection (URI, username,
>>     password);
>>                 // get query-service
>>                 XPathQueryService service =
>>                     (XPathQueryService) col.getService(
>>     "XPathQueryService", " 1.0" );
>>
>>                 // set pretty-printing on
>>                 service.setProperty(OutputKeys.INDENT, "yes" );
>>                 service.setProperty(OutputKeys.ENCODING , encoding);
>>
>>                 // execute query and get results in ResourceSet
>>                 ResourceSet result = service.query(query);
>>
>>                 for ( int i = 0; i < (int) result.getSize(); i++ ) {
>>
>>                     System.out.println ((String)((XMLResource)
>>     result.getResource( (long) i)).getContent());
>>                 }
>>
>>     When retrieving the XML document (which can be viewed via the
>>     Java client with no problems): -
>>
>>     <ADMIN id="1126626525826" created="13/09/2005 at 04:48"
>>     type="normal">
>>         <NAME first="Gareth" family="Hall"/>
>>         <EMAIL> [hidden email]
>>     <mailto:[hidden email]></EMAIL>
>>         <PASSWORD>f93fe2b182c016d7cb9b08981a3e26bc</PASSWORD>
>>     </ADMIN>
>>
>>     using the above code I running within Tomcat 5.5 I get the
>>     following output: -
>>
>>     <ADMIN id="1126626525826" created="13/09/2005 at 04:48"
>>     t??T??????(?????9♣5¶????
>>     ???↔????????????!??????(???☻♥?T?¶???v↨&WF??▬??♠▬66V?GW&R?6????T?¶???☻☻☻♥?♦§55t?$
>>     ??X?♫♫N♀XL?L????♂?►T????☼??♂?Q‼RS??
>>
>>     Does anybody have any idea why I am receiving this result?
>>
>>     Thank you for your help.
>>
>>     Gareth
>>
>>     --
>>     Gareth Hall
>>     Mobile: +44 (0) 7971037081
>
>
>
>
>
> --
> Gareth Hall
> Mobile: +44 (0) 7971037081





--
Gareth Hall
Mobile: +44 (0) 7971037081



--
Gareth Hall
Mobile: +44 (0) 7971037081
Loading...