0

尝试解析下面的 XML 时出现此错误。我正在通过 Eclipse 中的 Android 执行此操作。

XMLException:SAXException:在第 1 行,第 0 列:格式不正确(无效标记)

<?php
header('Content-type: text/xml');
echo '<wardrobe>
<item id="1">
    <path>images/pink.jpg</path>
    <name>pink top</name>
    <description>size 12 pink top</description>
    <category>tops</category>
</item>
<item id="2">
    <path>images/bluepants.jpg</path>
    <name>blue trousers</name>
    <description>size 10 light blue trousers</description>
    <category>bottoms</category>
</item>
<item id="3">
    <path>images/skirt.jpg</path>
    <name>grey skirt</name>
    <description>sze 10 grey skirt</description>
    <category>bottoms</category>
</item>
<item id="4">
    <path>images/runners.jpg</path>
    <name>runners</name>
    <description>exercise runners</description>
    <category>shoes</category>
</item>
<item id="5">
    <path>images/heels.jpg</path>
    <name>black heels</name>
    <description>dance shoes</description>
    <category>shoes</category>
</item>
</wardrobe>';
?>

我找不到这个无效令牌,我的 XML 看起来与 w3schools 示例相同: http ://www.w3schools.com/xml/xml_server.asp

任何人都可以发现这个令牌吗?

请帮助&谢谢。

4

1 回答 1

0

SAXparser 可能会抛出,因为您缺少文档声明。

w3schools 上的示例仅在这方面与您自己的代码不同。

<?php
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='ISO-8859-1'?>"; <-- This line.
echo "<note>";
echo "<from>Jani</from>";
echo "<to>Tove</to>";
echo "<message>Remember me this weekend</message>";
echo "</note>";
?>
于 2013-03-19T13:38:44.367 回答