Subject: RE: [xsl] How to escape invalid characters in XML to XML process From: "Roger Glover" <glover_roger@xxxxxxxxx> Date: Wed, 22 Jan 2003 01:50:02 -0600 |
Vijaya Kumar Y wrote: > Hi, > I'm receiving my input XML from an ASP page, and i get a lot of > invalid for > XML characters. How can I escape/convert these invalid characters for XML > into valid characters. In general, whenever I have this problem I always go back to whatever is generating the XML, in your case to the ASP page. It is much, much easier to filter out problem characters *before* you put them into the XML document than after you already have an ill-formed XML document. Assuming your ASP is not trying to add any non-printable characters ot the XML, it usually suffices to filter and replace characters as follows: For any text node child of an element: o "<" becomes "<" o "&" becomes "&" For any attribute value: o "<" becomes "<" o "&" becomes "&" o '"' becomes '"' (if you are using quote(") to delimit the attribute value) o "'" becomes "'" (if you are using apostrophe(') to delimit the attribute value) > I need to do this because after the > transformation I > post my output XML once again into a ASP page. This is the process: > getXML from ASP --> applyXSLT --> output XML --> validateXML(use Schema) > --> postXML to ASP > Can I do that in XSLT when I receive my input XML by matching these > characters and convert them? If yes, how? No, because XSLT entirely presupposes the well-formedness of the XML input. XSLT processing (at a given node at least) does not even begin until after parsing (which would have detected the ill-formed code and aborted there). > Validation is done by Schema. > Is there any template XSLT Script that does that? Schema validation via XSLT? Yes, that has been done. But it is not relevant here. Your problem is not document validation (that is, "does the document match the constraints of a DTD or set of schemata?"), but fundamental document well-formedness (that is, "Is this document an XML document at all?"). > Thank you for > your help. > If there aither ways of doing that, I would appreciate any pointers. Again, I think it all comes back to the ASP that is generating the XML in the first place. In the general case it is literally impossible to "fix" an illegal character ill-formedness problem automatically. In specific cases it is merely very, very difficult. You would have to write your own specialized XML parser with a sophisticated DTD- or schema-aware editing capability. In every case I have ever seen, it is simpler to just fix the problem at the source. -- Roger Glover glover_roger@xxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to escape invalid charact, Vijaya Kumar Y | Thread | RE: [xsl] How to escape invalid cha, Jarno . Elovirta |
RE: [xsl] How to escape invalid cha, Jarno . Elovirta | Date | RE: [xsl] debugging source line num, Dimitre Novatchev |
Month |