XML parse error [closed]
I have a Valid XML.
It asked me to treat the entire metadata record as the value of metadata element "dataxml", with newlines (and percent signs) indicated by percent signs (i.e. “percent-escaped”)
so i have done the following
Note: It asked me percent only the following : \n,\r, : and % so i only str_replaced those
$input .= 'dataxml: ' . str_replace(array(chr(hexdec('3A')),chr(hexdec('25')),chr(hexdec('0A')),chr(hexdec('0D'))),array('%3A', '%25', '%0A', '%0D'), $xmlfile) . "\n";
But it pops out the following error:
400 error:'dataxml': XML parse error: xmlns: URI http%253A//dataxml.org/schema/kernel-2.1 is not absolute
Can any one point out what i have done wrong?
The colon in http://
is being replaced twice: first the colon is replaced by %3A
then the percent in that replacement is being replaced by %25
.
You can use the function strtr()
to avoid replacing already replaced parts of the string.
For example,
$input .= 'dataxml: ' . strtr($xmlfile, array(":" => "%3A", "%" => "%25", "\n" => "%0A", "\r" => "%0D")) . "\n";
精彩评论