XMLPullparser getEventType returns 始终为 0
XMLPullparser getEventType returns 0 always
XmlPullParserFactory pullParserFactory = XmlPullParserFactory.newInstance();
pullParserFactory.setNamespaceAware(true);
XmlPullParser parser = pullParserFactory.newPullParser();
parser.setInput(new StringReader(xmlResponse.replace("&","&")));
int eventType = parser.getEventType();
在事件类型中,我总是只得到 0 并在 while 中循环。我的 Xml 回复是
<ResponseCode>00</ResponseCode>
<ResponseMessage>Success</ResponseMessage>
<CategoryCount>10</CategoryCount>
<CategoryMaster>
<CategoryId>001</CategoryId>
<CategoryFullName>BreakFast</CategoryFullName>
<CategoryShortName>Break</CategoryShortName>
<SubCategoryMaster>
<SubCategoryId>007</SubCategoryId>
<SubCategoryFullName>Idiyappam</SubCategoryFullName>
<SubCategoryShortName>idi</SubCategoryShortName>
<price>25.00</price>
</SubCategoryMaster>
</CategoryMaster>
请多多指教
这样使用。
XmlPullParserFactory pullParserFactory = XmlPullParserFactory.newInstance();
pullParserFactory.setNamespaceAware(true);
XmlPullParser parser = pullParserFactory.newPullParser();
parser.setInput(new StringReader(xmlResponse.replace("&","&")));
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag "+parser.getName());
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag "+parser.getName());
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("Text "+parser.getText());
}
eventType = parser.next();
}
XmlPullParserFactory pullParserFactory = XmlPullParserFactory.newInstance();
pullParserFactory.setNamespaceAware(true);
XmlPullParser parser = pullParserFactory.newPullParser();
parser.setInput(new StringReader(xmlResponse.replace("&","&")));
int eventType = parser.getEventType();
在事件类型中,我总是只得到 0 并在 while 中循环。我的 Xml 回复是
<ResponseCode>00</ResponseCode>
<ResponseMessage>Success</ResponseMessage>
<CategoryCount>10</CategoryCount>
<CategoryMaster>
<CategoryId>001</CategoryId>
<CategoryFullName>BreakFast</CategoryFullName>
<CategoryShortName>Break</CategoryShortName>
<SubCategoryMaster>
<SubCategoryId>007</SubCategoryId>
<SubCategoryFullName>Idiyappam</SubCategoryFullName>
<SubCategoryShortName>idi</SubCategoryShortName>
<price>25.00</price>
</SubCategoryMaster>
</CategoryMaster>
请多多指教
这样使用。
XmlPullParserFactory pullParserFactory = XmlPullParserFactory.newInstance();
pullParserFactory.setNamespaceAware(true);
XmlPullParser parser = pullParserFactory.newPullParser();
parser.setInput(new StringReader(xmlResponse.replace("&","&")));
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag "+parser.getName());
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag "+parser.getName());
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("Text "+parser.getText());
}
eventType = parser.next();
}