解析没有根元素的xml

时间:2011-06-20 19:13:24

标签: java android sax

人们!我从服务器获得了一个xml,我试图用Android SAX解析:

<?xml version="1.0" encoding="utf-8"?>
<News id="148364">
    <Title>Title</Title>
    <Desc>Desc</Desc>
    <Body>Body</Body>
    <Source_URL>example.url</Source_URL>
    <Source_Title>Title</Source_Title_Heb>
    <News_Date_Txt>20/06/11 18:14</News_Date_Txt>
    <News_Attachment>/Downloads/News_148364_1.htm</News_Attachment>
</News>

当我尝试执行以下操作时:

RootElement root=new RootElement("News");

我收到了例外:

android.sax.BadXmlException: root element name does not match. Expected "News", Got "http://www.w3.org/1999/xhtml:html"

它可能是什么?如何在没有root的情况下获取子节点?

1 个答案:

答案 0 :(得分:1)

尝试将SAXParser配置为不使用 XML架构验证

SAXParserFactory parser = SAXParserFactory.newInstance();
parser.setValidating(false);
parser.setNamespaceAware(false);