當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。