XML中非法字符的处理
即XML的Tag中间的内容如果包含如下字符的话( & < > ' " ),需要分别替换为对应的(& < > ' "),否则XML被解析时会报错。
1. 非法字符及替换
& => The ampersand (&).
< => The less than sign (<).
> => The greater than sign (>).
' => The single quote or apostrophe (').
" => The double quote (").
2. Perl替换程序
subConvertEntity
{
my($origin)=@_;
#<=>Thelessthansign(<).
#>=>Thegreaterthansign(>).
#&=>Theampersand(&).
#'=>Thesinglequoteorapostrophe(').
#"=>Thedoublequote(").
$origin=~s/&/&/g;
$origin=~s/</</g;
$origin=~s/>/>/g;
$origin=~s/'/'/g;
$origin=~s/"/"/g;

return($origin);
}

$string=qq{<and>and&and'and"};
printConvertEntity($string);
即XML的Tag中间的内容如果包含如下字符的话( & < > ' " ),需要分别替换为对应的(& < > ' "),否则XML被解析时会报错。
1. 非法字符及替换
& => The ampersand (&).
< => The less than sign (<).
> => The greater than sign (>).
' => The single quote or apostrophe (').
" => The double quote (").
2. Perl替换程序


















