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


Java XmlSerializer.setPrefix方法代码示例

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


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

示例1: writeToXmlImpl

import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
 * Serializes all Blocks in the given list and writes them to the either the output stream or
 * writer, whichever is not null.
 *
 * @param toSerialize A list of Blocks to serialize.
 * @param os An OutputStream to write the blocks to.
 * @param writer A writer to write the blocks to, if {@code os} is null.
 * @param options The options to configure the block serialization. If omitted,
 *                {@link IOOptions#WRITE_ALL_DATA} will be used by default.
 *
 * @throws BlocklySerializerException
 */
public static void writeToXmlImpl(final @NonNull List<Block> toSerialize,
                                  @Nullable OutputStream os, @Nullable Writer writer,
                                  @Nullable IOOptions options)
        throws BlocklySerializerException {
    final IOOptions finalOptions = options == null ? IOOptions.WRITE_ALL_DATA : options;
    XmlContentWriter contentWriter = new XmlContentWriter() {
        @Override
        public void write(XmlSerializer serializer) throws IOException {
            serializer.setPrefix("", XML_NAMESPACE);
            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

            serializer.startTag(XML_NAMESPACE, "xml");
            for (int i = 0; i < toSerialize.size(); i++) {
                toSerialize.get(i).serialize(serializer, true, finalOptions);
            }
            serializer.endTag(XML_NAMESPACE, "xml");
        }
    };
    try {
        if (os != null) {
            writeXml(os, contentWriter);
        } else {
            writeXml(writer, contentWriter);
        }
    } catch (IOException e) {
        throw new BlocklySerializerException(e);
    }
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:41,代码来源:BlocklyXmlHelper.java

示例2: writeToStream

import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
 * XML interface: procedure writes this list into the given stream
 */
public boolean writeToStream(OutputStream stream, String name)
{
    try
    {
        final StringWriter writer = new StringWriter();
        final XmlSerializer serializer = Xml.newSerializer();
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        serializer.setOutput(writer);
        serializer.startDocument("UTF-8", true);
        serializer.setPrefix(FormulaList.XML_PROP_MMT, FormulaList.XML_HTTP);
        serializer.startTag(FormulaList.XML_NS, FormulaList.XML_MAIN_TAG);
        serializer.startTag(FormulaList.XML_NS, XML_LIST_TAG);
        documentSettings.writeToXml(serializer);
        final ArrayList<FormulaBase> fList = formulaListView.getFormulas(FormulaBase.class);
        for (FormulaBase f : fList)
        {
            final String term = f.getBaseType().toString().toLowerCase(Locale.ENGLISH);
            serializer.startTag(FormulaList.XML_NS, term);
            f.writeToXml(serializer, String.valueOf(f.getId()));
            serializer.endTag(FormulaList.XML_NS, term);
        }
        serializer.endTag(FormulaList.XML_NS, XML_LIST_TAG);
        serializer.endTag(FormulaList.XML_NS, FormulaList.XML_MAIN_TAG);
        serializer.endDocument();
        stream.write(writer.toString().getBytes());
        return true;
    }
    catch (Exception e)
    {
        final String error = String.format(activity.getResources().getString(R.string.error_file_write), name);
        Toast.makeText(activity, error, Toast.LENGTH_LONG).show();
    }
    return false;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:38,代码来源:FormulaList.java

示例3: captureElement

import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
 * 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,代码行数:71,代码来源:BlocklyXmlHelper.java


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