|
即XML的Tag中間的內(nèi)容如果包含如下字符的話( & < > ' " ),需要分別替換為對(duì)應(yīng)的(& < > ' "),否則XML被解析時(shí)會(huì)報(bào)錯(cuò)。 1. 非法字符及替換 & => The ampersand (&). < => The less than sign (<). > => The greater than sign (>). ' => The single quote or apostrophe ('). " => The double quote ("). 2. Perl替換程序 sub ConvertEntity { my ($origin)=@_; # < => The less than sign (<). # > => The greater than sign (>). # & => The ampersand (&). # ' => The single quote or apostrophe ('). # " => The double quote ("). $origin =~s/&/&/g; $origin =~s/</</g; $origin =~s/>/>/g; $origin =~s/'/'/g; $origin =~s/"/"/g; return($origin); }![]() $string=qq{< and > and & and ' and "}; print ConvertEntity($string); |
|
|