本文整理匯總了Java中org.xmlpull.v1.XmlPullParser.IGNORABLE_WHITESPACE屬性的典型用法代碼示例。如果您正苦於以下問題:Java XmlPullParser.IGNORABLE_WHITESPACE屬性的具體用法?Java XmlPullParser.IGNORABLE_WHITESPACE怎麽用?Java XmlPullParser.IGNORABLE_WHITESPACE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.xmlpull.v1.XmlPullParser
的用法示例。
在下文中一共展示了XmlPullParser.IGNORABLE_WHITESPACE屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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.");
}