我正在尝试在我的 j2me 应用程序中解析一个简单的 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");