本文整理匯總了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);
}
}
示例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;
}
示例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.");
}