开发者

< none > tags - XML parsing using PHP

When I am parsing an XML file, there are some <none> tags that the system automatically generates for various fields... BUT, There are no </none> tags . So, my XML parser gives errors and is not parsing the ENTIRE file.

How do I get rid of this error?

$xml = simplexml_load_file($newfile3);  

<none&开发者_运维知识库gt; is not a tag ... So, I just want to ignore this or replace with something else like "none" ...


$newfile3 = str_replace('<none>', '&lt;none&gt;', $newfile3);

basically replace the bad 'tag' with the two metacharacters encoded into entities.


Zac, you should load the file first, then use the code from Marc B

$string = str_replace('<none>', 'your_replacement', file_get_contents($newfile3));
$xml = simplexml_load_string($string);

This should do the trick

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜