當前位置: 首頁>>代碼示例>>Java>>正文


Java Xml類代碼示例

本文整理匯總了Java中android.util.Xml的典型用法代碼示例。如果您正苦於以下問題:Java Xml類的具體用法?Java Xml怎麽用?Java Xml使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Xml類屬於android.util包,在下文中一共展示了Xml類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: inflateMenu

import android.util.Xml; //導入依賴的package包/類
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:19,代碼來源:FloatingSearchView.java

示例2: getDeviceData

import android.util.Xml; //導入依賴的package包/類
private static Set<DeviceFilter> getDeviceData(Resources resources, int xmlResourceId) {
    Set<DeviceFilter> ans = new HashSet<>();
    try {
        XmlResourceParser xml = resources.getXml(xmlResourceId);

        xml.next();
        int eventType;
        while ((eventType = xml.getEventType()) != XmlPullParser.END_DOCUMENT) {

            switch (eventType) {
                case XmlPullParser.START_TAG:
                    if (xml.getName().equals("usb-device")) {
                        AttributeSet as = Xml.asAttributeSet(xml);
                        Integer vendorId = parseInt( as.getAttributeValue(null, "vendor-id"));
                        Integer productId = parseInt( as.getAttributeValue(null, "product-id"));
                        ans.add(new DeviceFilter(vendorId, productId, null));
                    }
                    break;
            }
            xml.next();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return ans;
}
 
開發者ID:martinmarinov,項目名稱:AndroidDvbDriver,代碼行數:27,代碼來源:DeviceFilterXmlEquivalenceTester.java

示例3: generateServicesMap

import android.util.Xml; //導入依賴的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();
			}
		}
	}
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:27,代碼來源:VAccountManagerService.java

示例4: inflate

import android.util.Xml; //導入依賴的package包/類
public void inflate(int menuRes, Menu menu) {
    if (menu instanceof SupportMenu) {
        XmlResourceParser parser = null;
        try {
            parser = this.mContext.getResources().getLayout(menuRes);
            parseMenu(parser, Xml.asAttributeSet(parser), menu);
            if (parser != null) {
                parser.close();
            }
        } catch (XmlPullParserException e) {
            throw new InflateException("Error inflating menu XML", e);
        } catch (IOException e2) {
            throw new InflateException("Error inflating menu XML", e2);
        } catch (Throwable th) {
            if (parser != null) {
                parser.close();
            }
        }
    } else {
        super.inflate(menuRes, menu);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:SupportMenuInflater.java

示例5: generateServicesMap

import android.util.Xml; //導入依賴的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();
			}
		}
	}
}
 
開發者ID:codehz,項目名稱:container,代碼行數:27,代碼來源:VAccountManagerService.java

示例6: parseKeyboardLayoutSetElement

import android.util.Xml; //導入依賴的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();
    }
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:26,代碼來源:KeyboardLayoutSet.java

示例7: parseRowAttributes

import android.util.Xml; //導入依賴的package包/類
private KeyboardRow parseRowAttributes(final XmlPullParser parser)
        throws XmlPullParserException {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyboardAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard);
    try {
        if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap)) {
            throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "horizontalGap");
        }
        if (keyboardAttr.hasValue(R.styleable.Keyboard_verticalGap)) {
            throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "verticalGap");
        }
        return new KeyboardRow(mResources, mParams, parser, mCurrentY);
    } finally {
        keyboardAttr.recycle();
    }
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:17,代碼來源:KeyboardBuilder.java

示例8: parseKey

import android.util.Xml; //導入依賴的package包/類
private void parseKey(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_KEY, parser);
        if (DEBUG) startEndTag("<%s /> skipped", TAG_KEY);
        return;
    }
    final TypedArray keyAttr = mResources.obtainAttributes(
            Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
    final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
    final String keySpec = keyStyle.getString(keyAttr, R.styleable.Keyboard_Key_keySpec);
    if (TextUtils.isEmpty(keySpec)) {
        throw new ParseException("Empty keySpec", parser);
    }
    final Key key = new Key(keySpec, keyAttr, keyStyle, mParams, row);
    keyAttr.recycle();
    if (DEBUG) {
        startEndTag("<%s%s %s moreKeys=%s />", TAG_KEY, (key.isEnabled() ? "" : " disabled"),
                key, Arrays.toString(key.getMoreKeys()));
    }
    XmlParseUtils.checkEndTag(TAG_KEY, parser);
    endKey(key);
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:24,代碼來源:KeyboardBuilder.java

示例9: parseSpacer

import android.util.Xml; //導入依賴的package包/類
private void parseSpacer(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_SPACER, parser);
        if (DEBUG) startEndTag("<%s /> skipped", TAG_SPACER);
        return;
    }
    final TypedArray keyAttr = mResources.obtainAttributes(
            Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
    final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
    final Key spacer = new Key.Spacer(keyAttr, keyStyle, mParams, row);
    keyAttr.recycle();
    if (DEBUG) startEndTag("<%s />", TAG_SPACER);
    XmlParseUtils.checkEndTag(TAG_SPACER, parser);
    endKey(spacer);
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:17,代碼來源:KeyboardBuilder.java

示例10: parseKeyStyle

import android.util.Xml; //導入依賴的package包/類
private void parseKeyStyle(final XmlPullParser parser, final boolean skip)
        throws XmlPullParserException, IOException {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyStyleAttr = mResources.obtainAttributes(
            attr, R.styleable.Keyboard_KeyStyle);
    final TypedArray keyAttrs = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
    try {
        if (!keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_styleName)) {
            throw new XmlParseUtils.ParseException("<" + TAG_KEY_STYLE
                    + "/> needs styleName attribute", parser);
        }
        if (DEBUG) {
            startEndTag("<%s styleName=%s />%s", TAG_KEY_STYLE,
                    keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName),
                    skip ? " skipped" : "");
        }
        if (!skip) {
            mParams.mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser);
        }
    } finally {
        keyStyleAttr.recycle();
        keyAttrs.recycle();
    }
    XmlParseUtils.checkEndTag(TAG_KEY_STYLE, parser);
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:26,代碼來源:KeyboardBuilder.java

示例11: KeyboardRow

import android.util.Xml; //導入依賴的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;
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:18,代碼來源:KeyboardRow.java

示例12: Parse

import android.util.Xml; //導入依賴的package包/類
public List<RssItem> Parse(@NonNull InputStream inputStream) throws XmlPullParserException, IOException {
    try {
        XmlPullParser parser = Xml.newPullParser();

        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(inputStream, null);
        parser.nextTag();

        return readFeed(parser);
    } catch (Exception exception) {
        Logger.getInstance().Error(TAG, exception.getMessage());
    } finally {
        inputStream.close();
    }

    return null;
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-AndroidApplication,代碼行數:18,代碼來源:RssParser.java

示例13: FtcSongXml

import android.util.Xml; //導入依賴的package包/類
/**
 * Constructor: Create an instance of this object.
 *
 * @param instanceName specifies the instance name.
 * @param input specifies the input stream from which the notated song is read.
 */
public FtcSongXml(String instanceName, InputStream input) throws XmlPullParserException, IOException
{
    if (debugEnabled)
    {
        dbgTrace = new TrcDbgTrace(moduleName + "." + instanceName, tracingEnabled, traceLevel, msgLevel);
    }

    this.instanceName = instanceName;
    try
    {
        parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(input, null);
        parser.nextTag();
        parseCollection();
    }
    finally
    {
        input.close();
    }
}
 
開發者ID:trc492,項目名稱:Ftc2018RelicRecovery,代碼行數:28,代碼來源:FtcSongXml.java

示例14: parseFromPicasaXml

import android.util.Xml; //導入依賴的package包/類
/**
 * Parses photos XML (a list of photo; the contents of an album).
 * 
 * @param xmlStr
 *          the photo XML
 * @return a list of {@link Photo}s
 */
public static List<Photo> parseFromPicasaXml(String xmlStr) {
  PicasaPhotosSaxHandler handler = new PicasaPhotosSaxHandler();
  try {
    // The Parser somehow has some trouble with a plus sign in the
    // content. This is a hack to fix this.
    // TODO: Maybe we should replace all these special characters with
    // XML entities?
    xmlStr = xmlStr.replace("+", "&#43;");
    Xml.parse(xmlStr, handler);
    return handler.getPhotos();
  } catch (SAXException e) {
    Log.e("Photo", e.getMessage(), e);
  }
  return new ArrayList<Photo>();
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:23,代碼來源:Photo.java

示例15: generateServicesMap

import android.util.Xml; //導入依賴的package包/類
private void generateServicesMap(List<ResolveInfo> services, Map<String, SyncAdapterInfo> map,
                                 RegisteredServicesParser accountParser) {
    for (ResolveInfo info : services) {
        XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo, "android.content.SyncAdapter");
        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 ("sync-adapter".equals(parser.getName())) {
                    SyncAdapterType adapterType = parseSyncAdapterType(
                            accountParser.getResources(mContext, info.serviceInfo.applicationInfo), attributeSet);
                    if (adapterType != null) {
                        String key = adapterType.accountType + "/" + adapterType.authority;
                        map.put(key, new SyncAdapterInfo(adapterType, info.serviceInfo));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:26,代碼來源:VContentService.java


注:本文中的android.util.Xml類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。