0
我想解析我的j2me應用程序中的簡單XML文件。但分析失敗:kxml2解析簡單的XML
XML文件
<companies>
<company CompanyId="6">
<CompanyName>Test Company 1</CompanyName>
<SapNumber>0</SapNumber>
<RootCompanyId>1</RootCompanyId>
<ParentCompanyId /> </company>
</companies>
分析器片段
KXmlParser parser = new KXmlParser();
parser.setInput(new InputStreamReader(new ByteArrayInputStream(input.getBytes())));
parser.nextTag();
parser.require(XmlPullParser.START_TAG, null, "companies");
while(parser.nextTag() == XmlPullParser.START_TAG)
{
Company temp_company = new Company();
parser.require(XmlPullParser.START_TAG, null, "company");
String CompanyID = parser.getAttributeValue(0);
temp_company.putValue("CompanyId", CompanyID);
while(parser.nextTag() == XmlPullParser.START_TAG)
{
if(parser.getName() == "CompanyName")
{
temp_company.putValue("CompanyName", parser.nextText());
}
}
parser.require(XmlPullParser.END_TAG, null, "company");
listCompany.put(CompanyID, temp_company);
}
parser.require(XmlPullParser.END_TAG, null, "elements");
解析失敗如何?你有例外嗎? – kgiannakakis 2009-07-21 12:28:18