SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Threaded View

  1. #1
    SitePoint Zealot
    Join Date
    May 2003
    Location
    somewhere on the Earth
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xml question about storing special chars

    Hey I've got several questions about XML. Hope you can give me some idea.

    1. html entities.
    I know <, >, ', " and & should be converted to their html equivalents when stored in a xml file. but what about when & appears in a url address? for example:
    Code:
    <xml>
    	<url>http://whatever.com/index.php?user=whoever&do=whatever</url>
    	<attr url='http://whatever.com/index.php?user=whoever&do=whatever'> or another one</attr>
    </xml>
    should the & in the query part of the url be converted to &amp; also?


    2. CDATA
    CDATA sections begin with a <![CDATA[ and end with a ]]>. and it's said that I could store original <, >, ', " and &.

    but what about when the user inputs contains ]]> which is the close tag of the CDATA section? for example:
    Code:
    <xml>
    	<cdata><![CDATA][ so I can put < > ' " & here. but wait what if I put a "]]>" here? ]]></cdata>
    </xml>
    3. quotes in tags and attributes
    I know attributes value must be within two single/double quotes like:
    Code:
    <xml>
    	<attr1 value='some value here within two single quotes' />
    	<attr2 value="or some within two double quotes" />
    </xml>
    so when there is any ' or " in the value string, it should be converted to its html equivalent. but what about leaving a double quote " unchanged when it's within two single quotes ', and leaving a single quote' unchanged when it's within two double quotes " ? like the following:
    Code:
    <xml>
    	<attr1 value='a double quote " here within two single quotes' />
    	<attr2 value="or a single quote ' within two double quotes" />
    </xml>
    and also, if the quotes are in tags, like:
    Code:
    <xml>
    	<quote>JC said, " should I do this 'BAD' thing here?"</quote>
    </xml>
    I guess it might be ok to leave them there as they are, or am I totally wrong and I should change all of them in whatever place to &quot; and ' respectively?
    Last edited by zjcboy; Jul 13, 2004 at 07:10.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •