|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 & 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 " and ' respectively? |
|
#2
|
||||
|
||||
|
To keep it short and simple:
1. Yep, you should convert those to & 2. If a user puts ]]> to some input, you just need to prohibit this (JS,PHP, whatever you like...) 3. You can leave em as they are... -Miska- |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > xml question about storing special chars |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|