Java 类android.util.Xml 实例源码

项目:Hitalk    文件:FloatingSearchView.java   
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();
    }
}
项目:AndroidDvbDriver    文件:DeviceFilterXmlEquivalenceTester.java   
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;
}
项目:VirtualHook    文件:VAccountManagerService.java   
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();
            }
        }
    }
}
项目:boohee_v5.6    文件:SupportMenuInflater.java   
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);
    }
}
项目:container    文件:VAccountManagerService.java   
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();
            }
        }
    }
}
项目:simple-keyboard    文件:KeyboardLayoutSet.java   
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();
    }
}
项目:simple-keyboard    文件:KeyboardBuilder.java   
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();
    }
}
项目:simple-keyboard    文件:KeyboardBuilder.java   
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);
}
项目:simple-keyboard    文件:KeyboardBuilder.java   
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);
}
项目:simple-keyboard    文件:KeyboardBuilder.java   
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);
}
项目:simple-keyboard    文件:KeyboardRow.java   
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;
}
项目:LucaHome-AndroidApplication    文件:RssParser.java   
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;
}
项目:Ftc2018RelicRecovery    文件:FtcSongXml.java   
/**
 * 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();
    }
}
项目:buildAPKsSamples    文件:Photo.java   
/**
 * 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>();
}
项目:TPlayer    文件:VContentService.java   
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();
            }
        }
    }
}
项目:LeMondeRssReader    文件:RssParser.java   
@NonNull
ArrayList<RssItem> parse(String stream) {
    ArrayList<RssItem> items = null;
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(new StringReader(stream));
        parser.nextTag();
        parser.require(XmlPullParser.START_TAG, null, TAG_RSS);
        items = readFeed(parser);
    } catch (@NonNull XmlPullParserException | IOException e) {
        Log.w(e.getMessage(), e);
    } finally {
        if (items == null) {
            items = new ArrayList<>();
        }
    }
    return items;
}
项目:LucaHome-MediaServer    文件:RssParser.java   
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) {
        new SmartMirrorLogger(TAG).Error(exception.getMessage());
    } finally {
        inputStream.close();
    }

    return null;
}
项目:AOSP-Kayboard-7.1.2    文件:KeyboardBuilder.java   
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();
    }
}
项目:AOSP-Kayboard-7.1.2    文件:KeyboardBuilder.java   
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);
}
项目:AOSP-Kayboard-7.1.2    文件:KeyboardBuilder.java   
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);
}
项目:AOSP-Kayboard-7.1.2    文件:KeyboardBuilder.java   
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);
}
项目:AOSP-Kayboard-7.1.2    文件:KeyboardRow.java   
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;
}
项目:ararat    文件:SimpleXmlParser.java   
protected void parseXml(InputStream inputStream)
        throws XmlPullParserException, IOException
{
    mStack.clear();

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(false);

    XmlPullParser parser = factory.newPullParser();
    parser.setInput(inputStream, "UTF-8");
    parser.setFeature(Xml.FEATURE_RELAXED, true);

    int eventType = parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            mStack.push(parser.getName());
            onStartElement(new SimpleXmlPath(mStack), parser);
        } else if (eventType == XmlPullParser.END_TAG) {
            mStack.pop();
        } else if (eventType == XmlPullParser.TEXT) {
            onTextContent(new SimpleXmlPath(mStack), parser.getText());
        }

        eventType = parser.next();
    }
}
项目:ssj    文件:StrategyLoader.java   
public boolean load()
{
    InputStream inputStream = null;

    try
    {
        inputStream = new FileInputStream(strategyFile);
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(inputStream, null);

        parser.nextTag();
        parser.require(XmlPullParser.START_TAG, null, "ssj");
        parser.nextTag();
        parser.require(XmlPullParser.START_TAG, null, "strategy");
        loadStrategyComponents(parser);
        inputStream.close();
        addComponents();
        return true;
    }
    catch (IOException | XmlPullParserException | SSJFatalException e)
    {
        removeAddedComponents();
        return false;
    }
}
项目:ssj    文件:SimpleXmlParser.java   
/**
 * @param in               InputStream
 * @param searchPath       String[]
 * @param searchAttributes String[]
 * @return XmlValues
 * @throws XmlPullParserException
 * @throws IOException
 */
public XmlValues parse(InputStream in, String[] searchPath, String[] searchAttributes) throws XmlPullParserException, IOException
{
    this.searchPath = searchPath;
    this.searchAttributes = searchAttributes;
    xmlValues = new XmlValues();
    try
    {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(in, null);
        parser.nextTag();
        search(parser, 0);
        return xmlValues;
    } finally
    {
        in.close();
    }
}
项目:FtcSamples    文件:FtcSongXml.java   
/**
 * 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();
    }
}
项目:Connect-SDK-Cordova-Plugin    文件:DLNAService.java   
String parseData(String response, String key) {
    if (isXmlEncoded(response)) {
        response = Html.fromHtml(response).toString();
    }
    XmlPullParser parser = Xml.newPullParser();
    try {
        parser.setInput(new StringReader(response));
        int event;
        boolean isFound = false;
        do {
            event = parser.next();
            if (event == XmlPullParser.START_TAG) {
                String tag = parser.getName();
                if (key.equals(tag)) {
                    isFound = true;
                }
            } else if (event == XmlPullParser.TEXT && isFound) {
                return parser.getText();
            }
        } while (event != XmlPullParser.END_DOCUMENT);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}
项目:lr_dialer    文件:XmlDom.java   
private String serialize(Element e, int intent)
{
    try
    {
        XmlSerializer s = Xml.newSerializer();
        StringWriter sw = new StringWriter();
        s.setOutput(sw);
        s.startDocument("utf-8", null);
        String spaces = null;
        if (intent > 0)
        {
            char[] chars = new char[intent];
            Arrays.fill(chars, ' ');
            spaces = new String(chars);
        }
        serialize(root, s, 0, spaces);
        s.endDocument();
        return sw.toString();
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
    return null;
}
项目:PowerScore    文件:about.java   
public static UpdateInfo getUpdateInfo(InputStream is) throws Exception {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(is, "utf-8");
    int type = parser.getEventType();
    UpdateInfo info = new UpdateInfo();
    while (type != XmlPullParser.END_DOCUMENT) {
        switch (type) {
            case XmlPullParser.START_TAG:
                if ("version".equals(parser.getName())) {
                    info.setVersion(parser.nextText());
                } else if ("url".equals(parser.getName())) {
                    info.setUrl(parser.nextText());
                } else if ("description".equals(parser.getName())) {
                    info.setDescription(parser.nextText());
                }
                break;
        }
        type = parser.next();
    }
    return info;
}
项目:PowerScore    文件:UpdateManager.java   
public static UpdateInfo getUpdateInfo(InputStream is) throws Exception {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(is, "utf-8");
    int type = parser.getEventType();
    UpdateInfo info = new UpdateInfo();
    while (type != XmlPullParser.END_DOCUMENT) {
        switch (type) {
            case XmlPullParser.START_TAG:
                if ("version".equals(parser.getName())) {
                    info.setVersion(parser.nextText());
                } else if ("url".equals(parser.getName())) {
                    info.setUrl(parser.nextText());
                } else if ("description".equals(parser.getName())) {
                    info.setDescription(parser.nextText());
                }
                break;
        }
        type = parser.next();
    }
    return info;
}
项目:Scalpel_Android    文件:AbsBeanXmlParser.java   
public void parse(int xmlRes) {
    String nameSpace = mContext.getResources().getString(R.string.bean_name_space);
    try {
        XmlResourceParser parser = mContext.getResources().getXml(xmlRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG &&
                    parser.getName().equals(nameSpace)) {
                final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.bean);
                int id = a.getResourceId(R.styleable.bean_identify, 0);
                String name = a.getString(R.styleable.bean_nickname);
                String clz = a.getString(R.styleable.bean_clz);
                if (clz != null) {
                    onCreateBeanItem(new BeanItem(id, name, clz));
                }
                a.recycle();
            }
            eventType = parser.next();
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "Received exception parsing bean xml:" + Log.getStackTraceString(e));
    }
}
项目:TaskApp    文件:TasksXmlExporter.java   
private void doTasksExport(String output) throws IOException {
    File xmlFile = new File(output);
    xmlFile.createNewFile();
    FileOutputStream fos = new FileOutputStream(xmlFile);
    xml = Xml.newSerializer();
    xml.setOutput(fos, BackupConstants.XML_ENCODING);

    xml.startDocument(null, null);
    xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

    xml.startTag(null, BackupConstants.ASTRID_TAG);
    xml.attribute(null, BackupConstants.ASTRID_ATTR_VERSION,
            Integer.toString(preferences.getLastSetVersion()));
    xml.attribute(null, BackupConstants.ASTRID_ATTR_FORMAT,
            Integer.toString(FORMAT));

    serializeTasks();
    serializeTagDatas();

    xml.endTag(null, BackupConstants.ASTRID_TAG);
    xml.endDocument();
    xml.flush();
    fos.close();
}
项目:LucaHome-AndroidApplication    文件:RssParser.java   
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;
}
项目:Stringlate    文件:ApplicationListParser.java   
static ArrayList<ApplicationDetails> parseFromXml(InputStream in, HashSet<String> installedPackages)
        throws XmlPullParserException, IOException {

    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(in, null);
        parser.nextTag();

        ArrayList<ApplicationDetails> apps = readFdroid(parser);
        // Now set which applications are installed on the device
        for (ApplicationDetails app : apps) {
            if (installedPackages.contains(app.getPackageName()))
                app.setInstalled();
        }

        return apps;
    } finally {
        try {
            in.close();
        } catch (IOException ignored) {
        }
    }
}
项目:GComic    文件:FloatingSearchView.java   
public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes == 0) 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();
    }
}
项目:Accessories_Android    文件:AbsProcessorXmlParser.java   
public void parse(int xmlRes) {
    String nameSpace = mContext.getResources().getString(R.string.processor_ns);
    try {
        XmlResourceParser parser = mContext.getResources().getXml(xmlRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG &&
                    parser.getName().equals(nameSpace)) {
                final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.processor);
                String scope = a.getString(R.styleable.processor_scope);
                String clz = a.getString(R.styleable.processor_clazz);
                Preconditions.checkNotNull(scope);
                Preconditions.checkNotNull(clz);
                onCreateItem(new ProcessorItem(clz, scope));
                a.recycle();
            }
            eventType = parser.next();
        }
    } catch (Exception e) {
        LoggerManager.getLogger(getClass()).error("Received exception parsing bean xml:" + Log.getStackTraceString(e));
    }
}
项目:FloatingSearchView    文件:FloatingSearchView.java   
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();
    }
}
项目:LucaHome-MediaServer    文件:RssParser.java   
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) {
        new SmartMirrorLogger(TAG).Error(exception.getMessage());
    } finally {
        inputStream.close();
    }

    return null;
}
项目:LaunchEnr    文件:InvariantDeviceProfile.java   
private ArrayList<InvariantDeviceProfile> getPredefinedDeviceProfiles(Context context) {
    ArrayList<InvariantDeviceProfile> profiles = new ArrayList<>();
    try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
        final int depth = parser.getDepth();
        int type;

        while (((type = parser.next()) != XmlPullParser.END_TAG ||
                parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
            if ((type == XmlPullParser.START_TAG) && "profile".equals(parser.getName())) {
                TypedArray a = context.obtainStyledAttributes(
                        Xml.asAttributeSet(parser), R.styleable.InvariantDeviceProfile);
                int numRows = a.getInt(R.styleable.InvariantDeviceProfile_numRows, 0);
                int numColumns = a.getInt(R.styleable.InvariantDeviceProfile_numColumns, 0);
                float iconSize = a.getFloat(R.styleable.InvariantDeviceProfile_iconSize, 0);
                profiles.add(new InvariantDeviceProfile(
                        a.getString(R.styleable.InvariantDeviceProfile_name),
                        a.getFloat(R.styleable.InvariantDeviceProfile_minWidthDps, 0),
                        a.getFloat(R.styleable.InvariantDeviceProfile_minHeightDps, 0),
                        numRows,
                        numColumns,
                        a.getInt(R.styleable.InvariantDeviceProfile_numFolderRows, numRows),
                        a.getInt(R.styleable.InvariantDeviceProfile_numFolderColumns, numColumns),
                        a.getInt(R.styleable.InvariantDeviceProfile_minAllAppsPredictionColumns, numColumns),
                        iconSize,
                        a.getFloat(R.styleable.InvariantDeviceProfile_iconTextSize, 0),
                        a.getInt(R.styleable.InvariantDeviceProfile_numHotseatIcons, numColumns),
                        a.getFloat(R.styleable.InvariantDeviceProfile_hotseatIconSize, iconSize),
                        a.getResourceId(R.styleable.InvariantDeviceProfile_defaultLayoutId, 0)));
                a.recycle();
            }
        }
    } catch (IOException|XmlPullParserException e) {
        throw new RuntimeException(e);
    }
    return profiles;
}
项目:Ships    文件:UsbUtils.java   
private static void retrieveSupportedDevices(final Resources resources) {
    final String tag = "retrieveDeviceData - ";

    if (supportedDevices == null) {
        final List<SupportedDevice> result = new ArrayList<>();
        final XmlResourceParser xml = resources.getXml(R.xml.supported_devices);
        try {
            xml.next();
            int eventType;
            while ((eventType = xml.getEventType()) != XmlPullParser.END_DOCUMENT) {
                switch (eventType) {
                    case XmlPullParser.START_TAG:
                        if (xml.getName().equals("usb-device")) {
                            final AttributeSet as = Xml.asAttributeSet(xml);
                            final Integer vendorId = parseInt(as.getAttributeValue(null, "vendor-id"));
                            final Integer productId = parseInt(as.getAttributeValue(null, "product-id"));

                            // Read description
                            String description=null;
                            xml.next();
                            if (xml.getName().equals("description")) {
                                xml.require(XmlPullParser.START_TAG, null, "description");
                                if (xml.next() == XmlPullParser.TEXT) {
                                    description = xml.getText();
                                    xml.nextTag();
                                }

                                xml.require(XmlPullParser.END_TAG, null, "description");
                            }
                            result.add(new SupportedDevice(new Pair<>(vendorId, productId), description));
                        }
                        break;
                }
                xml.next();
            }
        } catch (XmlPullParserException | IOException e) {
            Log.e(TAG, tag, e);
        }

        supportedDevices = result;
    }
}