本文整理匯總了Java中org.xmlpull.v1.XmlPullParser類的典型用法代碼示例。如果您正苦於以下問題:Java XmlPullParser類的具體用法?Java XmlPullParser怎麽用?Java XmlPullParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
XmlPullParser類屬於org.xmlpull.v1包,在下文中一共展示了XmlPullParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getIcons
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private Set<String> getIcons() {
// Set<String> iconSet = new TreeSet<>(); // 字母順序
Set<String> iconSet = new LinkedHashSet<>(); // 錄入順序
XmlResourceParser parser = getResources().getXml(R.xml.drawable);
try {
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
if (!"item".equals(parser.getName())) {
event = parser.next();
continue;
}
iconSet.add(parser.getAttributeValue(null, "drawable"));
}
event = parser.next();
}
} catch (Exception e) {
e.printStackTrace();
}
return iconSet;
}
示例2: generateServicesMap
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private void generateServicesMap(List<ResolveInfo> services, Map<String, AuthenticatorInfo> map,
IAccountParser accountParser) {
for (ResolveInfo info : services) {
XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo,
AccountManager.AUTHENTICATOR_META_DATA_NAME);
if (parser != null) {
try {
AttributeSet attributeSet = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Nothing to do
}
if (AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME.equals(parser.getName())) {
AuthenticatorDescription desc = parseAuthenticatorDescription(
accountParser.getResources(mContext, info.serviceInfo.applicationInfo),
info.serviceInfo.packageName, attributeSet);
if (desc != null) {
map.put(desc.type, new AuthenticatorInfo(desc, info.serviceInfo));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
示例3: KeyboardRow
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
public KeyboardRow(final Resources res, final KeyboardParams params,
final XmlPullParser parser, final int y) {
mParams = params;
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
mRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_rowHeight, params.mBaseHeight, params.mDefaultRowHeight);
keyboardAttr.recycle();
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
mRowAttributesStack.push(new RowAttributes(
keyAttr, params.mDefaultKeyWidth, params.mBaseWidth));
keyAttr.recycle();
mCurrentY = y;
mCurrentX = 0.0f;
}
示例4: init
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private boolean init(@NonNull Resources resources) {
try {
XmlResourceParser parser = resources.getXml(R.xml.appfilter);
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
if (!"item".equals(parser.getName())) {
event = parser.next();
continue;
}
String drawable = parser.getAttributeValue(null, "drawable");
if (TextUtils.isEmpty(drawable)) {
event = parser.next();
continue;
}
String component = parser.getAttributeValue(null, "component");
if (TextUtils.isEmpty(component)) {
event = parser.next();
continue;
}
Matcher matcher = componentPattern.matcher(component);
if (!matcher.matches()) {
event = parser.next();
continue;
}
dataList.add(new Bean(matcher.group(1), matcher.group(2), drawable));
}
event = parser.next();
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例5: parseServerSettings
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private static ImportedServer parseServerSettings(XmlPullParser xpp, String endTag)
throws XmlPullParserException, IOException {
ImportedServer server = new ImportedServer();
server.type = xpp.getAttributeValue(null, SettingsExporter.TYPE_ATTRIBUTE);
int eventType = xpp.next();
while (!(eventType == XmlPullParser.END_TAG && endTag.equals(xpp.getName()))) {
if (eventType == XmlPullParser.START_TAG) {
String element = xpp.getName();
if (SettingsExporter.HOST_ELEMENT.equals(element)) {
server.host = getText(xpp);
} else if (SettingsExporter.PORT_ELEMENT.equals(element)) {
server.port = getText(xpp);
} else if (SettingsExporter.CONNECTION_SECURITY_ELEMENT.equals(element)) {
server.connectionSecurity = getText(xpp);
} else if (SettingsExporter.AUTHENTICATION_TYPE_ELEMENT.equals(element)) {
String text = getText(xpp);
server.authenticationType = AuthType.valueOf(text);
} else if (SettingsExporter.USERNAME_ELEMENT.equals(element)) {
server.username = getText(xpp);
} else if (SettingsExporter.CLIENT_CERTIFICATE_ALIAS_ELEMENT.equals(element)) {
server.clientCertificateAlias = getText(xpp);
} else if (SettingsExporter.PASSWORD_ELEMENT.equals(element)) {
server.password = getText(xpp);
} else if (SettingsExporter.EXTRA_ELEMENT.equals(element)) {
server.extras = parseSettings(xpp, SettingsExporter.EXTRA_ELEMENT);
} else {
Timber.w("Unexpected start tag: %s", xpp.getName());
}
}
eventType = xpp.next();
}
return server;
}
示例6: parseFolders
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private static List<ImportedFolder> parseFolders(XmlPullParser xpp) throws XmlPullParserException, IOException {
List<ImportedFolder> folders = null;
int eventType = xpp.next();
while (!(eventType == XmlPullParser.END_TAG && SettingsExporter.FOLDERS_ELEMENT.equals(xpp.getName()))) {
if (eventType == XmlPullParser.START_TAG) {
String element = xpp.getName();
if (SettingsExporter.FOLDER_ELEMENT.equals(element)) {
if (folders == null) {
folders = new ArrayList<>();
}
ImportedFolder folder = parseFolder(xpp);
folders.add(folder);
} else {
Timber.w("Unexpected start tag: %s", xpp.getName());
}
}
eventType = xpp.next();
}
return folders;
}
示例7: f
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private static String f(XmlPullParser xmlPullParser) {
String str = "";
int depth = xmlPullParser.getDepth();
while (true) {
if (xmlPullParser.next() == 3 && xmlPullParser.getDepth() == depth) {
return str;
}
str = str + xmlPullParser.getText();
}
}
示例8: readThemeSetting
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
/***
* Public method that read information about theme settings from XML file
* @param parser the current parser used to parse the XML file
* @return ThemeSetting contains loaded settings
* @throws XmlPullParserException
* @throws IOException
*/
private ThemeSetting readThemeSetting(XmlPullParser parser) throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, null, "themesetting");
ArrayMap<String, String> newValues = new ArrayMap<>();
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("font")) {
newValues.put("font", readText(parser));
} else if (name.equals("palette")) {
newValues.put("palette", readText(parser));
} else if (name.equals("highlight")) {
newValues.put("highlight", readText(parser));
}
}
ThemeSetting themesetting = new ThemeSetting();
themesetting.changeSetting(newValues);
return themesetting;
}
示例9: parseLayout
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
/**
* Parses the layout and returns the number of elements added on the homescreen.
*/
protected int parseLayout(int layoutId, ArrayList<Long> screenIds)
throws XmlPullParserException, IOException {
XmlResourceParser parser = mSourceRes.getXml(layoutId);
beginDocument(parser, mRootTag);
final int depth = parser.getDepth();
int type;
HashMap<String, TagParser> tagParserMap = getLayoutElementsMap();
int count = 0;
while (((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
count += parseAndAddNode(parser, tagParserMap, screenIds);
}
return count;
}
示例10: parseKeyboardLayoutSetElement
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private void parseKeyboardLayoutSetElement(final XmlPullParser parser)
throws XmlPullParserException, IOException {
final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.KeyboardLayoutSet_Element);
try {
XmlParseUtils.checkAttributeExists(a,
R.styleable.KeyboardLayoutSet_Element_elementName, "elementName",
TAG_ELEMENT, parser);
XmlParseUtils.checkAttributeExists(a,
R.styleable.KeyboardLayoutSet_Element_elementKeyboard, "elementKeyboard",
TAG_ELEMENT, parser);
XmlParseUtils.checkEndTag(TAG_ELEMENT, parser);
final ElementParams elementParams = new ElementParams();
final int elementName = a.getInt(
R.styleable.KeyboardLayoutSet_Element_elementName, 0);
elementParams.mKeyboardXmlId = a.getResourceId(
R.styleable.KeyboardLayoutSet_Element_elementKeyboard, 0);
elementParams.mAllowRedundantMoreKeys = a.getBoolean(
R.styleable.KeyboardLayoutSet_Element_allowRedundantMoreKeys, true);
mParams.mKeyboardLayoutSetElementIdToParamsMap.put(elementName, elementParams);
} finally {
a.recycle();
}
}
示例11: readFeatures
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private List<Features> readFeatures(XmlPullParser parser) throws XmlPullParserException {
final List<Features> result = new ArrayList<>();
try {
parser.require(XmlPullParser.START_TAG, null, FEATURES);
while(parser.next() != XmlPullParser.END_TAG){
if(parser.getEventType() != XmlPullParser.START_TAG){
continue;
}
String name = parser.getName();
if (name.equals(FEATURES)) {
result.add(Features.valueOf(readText(parser)));
}
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
示例12: skip
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private static void skip(final XmlPullParser parser) throws XmlPullParserException,
IOException {
if (parser.getEventType() != XmlPullParser.START_TAG) {
throw new IllegalStateException();
}
int depth = 1;
while (depth != 0) {
switch (parser.next()) {
case XmlPullParser.END_TAG:
depth--;
break;
case XmlPullParser.START_TAG:
depth++;
break;
default:
break;
}
}
}
示例13: processTag
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
/**
* Processes the task required in the grammar to the given tag type
*
* @param container the DSML container
* @param tagType the tag type
* @throws XmlPullParserException when an error occurs during the parsing
*/
private static void processTag( Dsmlv2Container container, int tagType ) throws XmlPullParserException
{
XmlPullParser xpp = container.getParser();
String tagName = Strings.lowerCase( xpp.getName() );
GrammarTransition transition = container.getTransition( container.getState(), new Tag( tagName, tagType ) );
if ( transition != null )
{
container.setState( transition.getNextState() );
if ( transition.hasAction() )
{
transition.getAction().action( container );
}
}
else
{
throw new XmlPullParserException( I18n.err( I18n.ERR_03036, new Tag( tagName, tagType ) ), xpp, null );
}
}
示例14: newFilter
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
@Override
public Filter newFilter(XmlPullParser parser) throws IOException, XmlPullParserException {
String typeString = parser.getAttributeValue(null, ATTR_TYPE);
if (typeString == null) {
throw new XmlPullParserException("type attribute must be specified for <sender>",
parser, null);
}
if (typeString.equals(VAL_SYSTEM)) {
return SYSTEM;
} else if (typeString.equals(VAL_SIGNATURE)) {
return SIGNATURE;
} else if (typeString.equals(VAL_SYSTEM_OR_SIGNATURE)) {
return SYSTEM_OR_SIGNATURE;
} else if (typeString.equals(VAL_USER_ID)) {
return USER_ID;
}
throw new XmlPullParserException(
"Invalid type attribute for <sender>: " + typeString, parser, null);
}
示例15: readPropStat
import org.xmlpull.v1.XmlPullParser; //導入依賴的package包/類
private Response.PropStat readPropStat(XmlPullParser parser) throws IOException, XmlPullParserException {
Response.PropStat propstat = new Response.PropStat();
parser.require(XmlPullParser.START_TAG, ns, "propstat");
android.util.Log.d("PARSE", "readPropStat");
while (parser.next() != XmlPullParser.END_TAG) {
android.util.Log.d("PARSE", "3eventtype=" + parser.getEventType());
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
android.util.Log.d("PARSE", "3name=" + name);
if (name.equals("prop"))
{
propstat.prop = readProp(parser);
} else if (name.equals("status"))
{
propstat.status = readText(parser);
} else {
skip(parser);
}
}
return propstat;
}