This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, Can any one tell me how to use replace function in XSD to replace the character '&' by '&'. Here the character '&' appears as a data in my xml file, and because of this my xml processing fails. I am using SAX parser for this. Thanks.
If your XML file contains the character "&" as data outside a CDATA block, it's simply not a valid XML file. The long-term solution is to sort out whatever/whoever is generating this invalid file. In the real world, of course, we don't always have that option. I suggest you are going to have to pre-process your invalid XML file with a non-XML tool or program first. I doubt that much XML-based software will accept it at all, and if it does, it may just ignore the offending characters. The end result of the pre-processing should be to ensure that all invalid uses of "&" are replaced by an entity reference "& amp;". The tricky bit is to recognize which are valid uses (where it already forms part of an entity reference) so they don't get inadvertently converted too. In the general case this is surprisingly hard. However, in your particular case you may know more about your XML data feed which can make it easier in this case. If you only get these rogue characters inside one element, for example, you can restrict your processing to just the content of that element. You may be able to get away with just wrapping the content of that element in a CDATA block, or you may know that whatever generates that content is unaware of XML and will never generate entity references that should not be escaped. With out a bit more detail of your particular problem, I can't offer any more general help. Has this been useful, though? [ September 04, 2003: Message edited by: Frank Carver ]