• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error on '& ' in the XML text

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While parsing an XML file in which one of the tag is having "&", I am getting the org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.

I understand that it can be resolved if the & is passed instead of &, but the input is directly coming from user, and we can not enforce this.

Is there any other way to resolve this issue ?

[ June 02, 2006: Message edited by: Krish Lee ]

[ June 02, 2006: Message edited by: Krish Lee ]

[ June 02, 2006: Message edited by: Krish Lee ]
[ June 02, 2006: Message edited by: Krish Lee ]
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Krish Lee:
but the input is directly coming from user, and we can not enforce this.

Too bad. You will have to enforce it. XML parsers are not allowed to try to repair bozo XML. Perhaps it might be better to rework your system so that you don't require people to type XML into a text editor. Or provide them with tools to check the XML for well-formedness before sending it to you.
 
Krish Lee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul. The system actually is not asking user to enter the complete XML, but is requesting various text fields, which are then being arranged as String XML and are being passed to the service APIs.

So we can always make the change to replace the unsupported XML characters to the appropriate supported format (http://www.w3.org/TR/REC-xml/#syntax )in the string before passing it for further processing. But I was wondering if this is the only possible solution or there is some other workaround too. Any thoughts ?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, it's your code that's generating the bad XML. So all you have to do is to escape the characters that need to be escaped. That's just the rules of XML, I don't know why you would consider it to be a "workaround".

I have used SAX filters connected to an identity Transformer to produce XML. That way the XML software generates the document and it does it correctly. You could see an example of that here:

http://www.cafeconleche.org/books/xmljava/chapters/ch08s05.html
reply
    Bookmark Topic Watch Topic
  • New Topic