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.
Joined: May 31, 2006
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 ?
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: