This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Castors : how to handle garbage characters in XML using  RSS feed

 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi All,

My application uses castor API to parse a XML request file.
This file is generated by another application.
Now that program is writing some garbage characters in the very starting of the XML.
If the root tag is then the request file has written before it as :

Hence, I get a parsing error.

Can I handle these characters using castor API, or it would be helpful if I could know the possible reason for the occurance of these strange characters in the request.

Thanks in advance.
[ November 24, 2008: Message edited by: Aniruddh Joshi ]
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a Byte-order Mark. It's a legitimate part of an XML document, if it's present, but for some unknown reason none of the common XML parsers written in Java can deal with it.

You can deal with it by wrapping your input to the parser in a PushbackInputStream which starts out by reading all bytes until it finds a "<" and then backs up one, so the parser will start at the right place.
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul,
I have a problem using PushBackInoutStream , I am not using inputStream in my application for reading xml, a byte array is read instead.
This byte array is directly changed into a String and processed.

Is there a way compatible with my approach ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!