本文整理汇总了Java中org.xmlpull.v1.XmlPullParser.nextToken方法的典型用法代码示例。如果您正苦于以下问题:Java XmlPullParser.nextToken方法的具体用法?Java XmlPullParser.nextToken怎么用?Java XmlPullParser.nextToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmlpull.v1.XmlPullParser
的用法示例。
在下文中一共展示了XmlPullParser.nextToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lenientNextToken
import org.xmlpull.v1.XmlPullParser; //导入方法依赖的package包/类
static int lenientNextToken(XmlPullParser xpp) throws IOException, XmlPullParserException {
try {
return xpp.nextToken();
} catch (XmlPullParserException e) {
return xpp.getEventType();
}
}
示例2: readFromXml
import org.xmlpull.v1.XmlPullParser; //导入方法依赖的package包/类
public void readFromXml(XmlPullParser parser)
{
clear();
try
{
// On android version < 11, the standard XmlPullParser implementation has a bug:
// it throws a UnsupportedOperationException at getting CDSECT using nextToken().
// Therefore, XmlPullParserFactory.newInstance().newPullParser() shall be used
// to create parser instance in order to get it worked on Android versions 8-10.
final String type = parser.getAttributeValue(null, XML_PROP_IMAGE_TYPE);
if (type == null)
{
throw new Exception("image type is unknown");
}
final int event = parser.nextToken();
if (event == XmlPullParser.CDSECT)
{
final String imageText = parser.getText();
if (imageText == null || imageText.length() == 0)
{
throw new Exception("empty CDSECT");
}
byte[] imageDecoded = Base64.decode(imageText, BASE64_OPTIONS);
if (imageDecoded == null)
{
throw new Exception("cannot decode image, string lenght = " + imageText.length());
}
if (XML_PROP_IMAGE_PNG.equalsIgnoreCase(type))
{
ByteArrayInputStream imageStream = new ByteArrayInputStream(imageDecoded);
setBitmap(BitmapFactory.decodeStream(imageStream));
imageStream.close();
}
else if (XML_PROP_IMAGE_SVG.equalsIgnoreCase(type))
{
setSvg(new String(imageDecoded));
}
}
else
{
throw new Exception("CDSECT is not found");
}
}
catch (Exception e)
{
ViewUtils.Debug(this, e.getLocalizedMessage());
}
}