当前位置: 首页>>代码示例>>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;未经允许,请勿转载。