当前位置: 首页>>代码示例>>Java>>正文


Java XmlPullParser.CDSECT属性代码示例

本文整理汇总了Java中org.xmlpull.v1.XmlPullParser.CDSECT属性的典型用法代码示例。如果您正苦于以下问题:Java XmlPullParser.CDSECT属性的具体用法?Java XmlPullParser.CDSECT怎么用?Java XmlPullParser.CDSECT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.xmlpull.v1.XmlPullParser的用法示例。


在下文中一共展示了XmlPullParser.CDSECT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: captureElement

/**
 * Serializes the current element and all child nodes as a String.
 * @param parser The parser to pull from.
 * @return The composed element string.
 * @throws XmlPullParserException
 * @throws IOException
 */
public static String captureElement(XmlPullParser parser)
        throws XmlPullParserException, IOException
{
    int event = parser.getEventType();
    if (event != XmlPullParser.START_TAG) {
        throw new XmlPullParserException("Expected call to begin at START_TAG");
    }
    int depth = 0;

    StringWriter sw = new StringWriter();
    XmlSerializer serializer = PARSER_FACTORY.newSerializer();
    serializer.setOutput(sw);

    String namespace, prefix;
    while (event != XmlPullParser.END_DOCUMENT) {
        switch (event) {
            case XmlPullParser.START_TAG:
                ++depth;
                namespace = parser.getNamespace();
                prefix = parser.getPrefix();
                if (namespace != null && prefix != null) {
                    serializer.setPrefix(prefix, namespace);
                }
                serializer.startTag(namespace, parser.getName());
                int attrCount = parser.getAttributeCount();
                for (int i = 0; i < attrCount; ++i) {
                    namespace = parser.getAttributeNamespace(i);
                    prefix = parser.getAttributePrefix(i);
                    if (namespace != null && prefix != null) {
                        serializer.setPrefix(prefix, namespace);
                    }
                    serializer.attribute(namespace, parser.getAttributeName(i),
                            parser.getAttributeValue(i));
                }
                break;

            case XmlPullParser.TEXT:
            case XmlPullParser.IGNORABLE_WHITESPACE:
                serializer.text(parser.getText());
                break;

            case XmlPullParser.CDSECT:
                serializer.cdsect(parser.getText());
                break;

            case XmlPullParser.END_TAG:
                namespace = parser.getNamespace();
                if (namespace != null) {
                    serializer.setPrefix(parser.getPrefix(), namespace);
                }
                serializer.endTag(namespace, parser.getName());
                --depth;
                break;
        }
        if (depth <= 0) {
            serializer.flush();
            return sw.toString();
        }

        event = parser.next();
    }
    throw new IOException("Unexpected end of document.");
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:70,代码来源:BlocklyXmlHelper.java

示例2: readFromXml

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());
    }
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:48,代码来源:CustomImageView.java


注:本文中的org.xmlpull.v1.XmlPullParser.CDSECT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。