|
Posted by Jochem Maas on 12/28/05 13:19
Richard Lynch wrote:
> I'm creating some XML data, but not using any of the built-in PHP XML
> functions, as they are not necessarily available on all servers.
>
> I need to encode Data (CDATA) such as URLs etc.
>
> htmlspecialchars() works on all my test cases so far, but is it
> "right"?...
I don't think so - not completely - actually this is shaky ground for
me but one I'm very interested in (encoding/charsets/etc).
I'm pretty sure you can do this for example:
<sometag>
<![CDATA[<em>This is <a href="www.iamjochem.com/?i=1&j=2">HTML</a></em>]]>
</sometag>
now I don't think that an XML parser will care if the href attribute's value is
encoded properly (e.g. the '&' given as '&') because the whole CDATA block
is just a string (UTF8 is the default everywhere I have played with XML, so beware
that if you don't specify your character encoding that ti might cause hiccups).
so in the case above wether you entity encoding the url or not is pureluy a matter
of how valid do you want the HTML that one can extract from the CDATA block
inside the <sometag> tag.
the following urls might throw some light on the issue for you:
http://xmlrpc-epi.sourceforge.net/main.php?t=samples
http://blogs.law.harvard.edu/tech/encodingDescriptions
>
> Please cc: me on replies -- I'm way behind on PHP General reading... :-(
>
Navigation:
[Reply to this message]
|