当前位置: 首页>>代码示例>>Java>>正文


Java KXmlParser.setFeature方法代码示例

本文整理汇总了Java中org.kxml2.io.KXmlParser.setFeature方法的典型用法代码示例。如果您正苦于以下问题:Java KXmlParser.setFeature方法的具体用法?Java KXmlParser.setFeature怎么用?Java KXmlParser.setFeature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.kxml2.io.KXmlParser的用法示例。


在下文中一共展示了KXmlParser.setFeature方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getXMLResponse

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public static Document getXMLResponse (Reader reader) {
    Document doc = new Document();

    try{
        KXmlParser parser = new KXmlParser();
        parser.setInput(reader);
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        doc.parse(parser);
    } catch (Exception e) {
        System.err.println("couldn't process response payload from server!!");
        doc = null;
    }

    try {
        doc.getRootElement();
    } catch (RuntimeException re) {
        doc = null; //work around kxml bug where it should have failed to parse xml (doc == null)
                    //but instead returned an empty doc that throws an exception when you try to
                    //get its root element
    }

    return doc;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:25,代码来源:CommUtil.java

示例2: hasLayoutParams

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
@VisibleForTesting
static boolean hasLayoutParams(@NonNull Reader reader)
        throws XmlPullParserException, IOException {
    KXmlParser parser = new KXmlParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    parser.setInput(reader);

    while (true) {
        int event = parser.next();
        if (event == XmlPullParser.START_TAG) {
            for (int i = 0; i < parser.getAttributeCount(); i++) {
                if (parser.getAttributeName(i).startsWith(ATTR_LAYOUT_RESOURCE_PREFIX)) {
                    String prefix = parser.getAttributePrefix(i);
                    if (prefix != null && !prefix.isEmpty() &&
                            ANDROID_URI.equals(parser.getNamespace(prefix))) {
                        return true;
                    }
                }
            }

            return false;
        } else if (event == XmlPullParser.END_DOCUMENT) {
            return false;
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:LayoutInflationDetector.java

示例3: newPullParser

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
/**
 * Returns a new pull parser with namespace support.
 */
public static XmlPullParser newPullParser() {
    try {
        KXmlParser parser = new KXmlParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        return parser;
    } catch (XmlPullParserException e) {
        throw new AssertionError();
    }
}
 
开发者ID:Gracker,项目名称:Android-Framework-Tools-Utils,代码行数:14,代码来源:Xml.java

示例4: newPullParser

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
/**
     * Returns a new pull parser with namespace support.
     */
    private static XmlPullParser newPullParser() {
        try {
            KXmlParser parser = new KXmlParser();
//            parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
            return parser;
        } catch (XmlPullParserException e) {
            throw new AssertionError(e);
        }
    }
 
开发者ID:evant,项目名称:parsnip,代码行数:14,代码来源:XmlAdapter.java

示例5: getDocumentFromStream

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public static Document getDocumentFromStream(InputStream is) {
    KXmlParser parser = new KXmlParser();

    Document document = new Document();

    try {
        InputStreamReader reader = new InputStreamReader(is, "UTF-8");
        parser.setInput(reader);
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        document.parse(parser);
        return document;
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:16,代码来源:XmlComparator.java

示例6: parse

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public static XmlNode parse(Reader reader, boolean ignoreWhitespaces) throws Exception {
    KXmlParser parser = new KXmlParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    parser.setInput(reader);
    parser.next();
    XmlNode node = _parse(parser, ignoreWhitespaces);

    return node;
}
 
开发者ID:Ericsson-LMF,项目名称:IoT-Gateway,代码行数:10,代码来源:XmlParser.java

示例7: createReferenceParser

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
private static KXmlParser createReferenceParser(PsiFile file) throws XmlPullParserException {
  KXmlParser referenceParser = new KXmlParser();
  referenceParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
  referenceParser.setInput(new StringReader(file.getText()));
  return referenceParser;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:LayoutPsiPullParserTest.java

示例8: parse

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
@Override
public Document parse(InputSource source) throws SAXException, IOException {
    if (source == null) {
        throw new IllegalArgumentException("source == null");
    }

    String namespaceURI = null;
    String qualifiedName = null;
    DocumentType doctype = null;
    String inputEncoding = source.getEncoding();
    String systemId = source.getSystemId();
    DocumentImpl document = new DocumentImpl(
            dom, namespaceURI, qualifiedName, doctype, inputEncoding);
    document.setDocumentURI(systemId);

    KXmlParser parser = new KXmlParser();
    try {
        parser.keepNamespaceAttributes();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware);

        if (source.getByteStream() != null) {
            parser.setInput(source.getByteStream(), inputEncoding);
        } else if (source.getCharacterStream() != null) {
            parser.setInput(source.getCharacterStream());
        } else if (systemId != null) {
            URL url = new URL(systemId);
            URLConnection urlConnection = url.openConnection();
            urlConnection.connect();
            // TODO: if null, extract the inputEncoding from the Content-Type header?
            parser.setInput(urlConnection.getInputStream(), inputEncoding);
        } else {
            throw new SAXParseException("InputSource needs a stream, reader or URI", null);
        }

        if (parser.nextToken() == XmlPullParser.END_DOCUMENT) {
            throw new SAXParseException("Unexpected end of document", null);
        }

        parse(parser, document, document, XmlPullParser.END_DOCUMENT);

        parser.require(XmlPullParser.END_DOCUMENT, null, null);
    } catch (XmlPullParserException ex) {
        if (ex.getDetail() instanceof IOException) {
            throw (IOException) ex.getDetail();
        }
        if (ex.getDetail() instanceof RuntimeException) {
            throw (RuntimeException) ex.getDetail();
        }

        LocatorImpl locator = new LocatorImpl();

        locator.setPublicId(source.getPublicId());
        locator.setSystemId(systemId);
        locator.setLineNumber(ex.getLineNumber());
        locator.setColumnNumber(ex.getColumnNumber());

        SAXParseException newEx = new SAXParseException(ex.getMessage(), locator);

        if (errorHandler != null) {
            errorHandler.error(newEx);
        }

        throw newEx;
    } finally {
        IoUtils.closeQuietly(parser);
    }

    return document;
}
 
开发者ID:thahn0720,项目名称:agui_framework,代码行数:70,代码来源:DocumentBuilderImpl.java

示例9: parse

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
@Override
public Document parse(InputSource source) throws SAXException, IOException {
    if (source == null) {
        throw new IllegalArgumentException();
    }

    String namespaceURI = null;
    String qualifiedName = null;
    DocumentType doctype = null;
    String inputEncoding = source.getEncoding();
    String systemId = source.getSystemId();
    DocumentImpl document = new DocumentImpl(
            dom, namespaceURI, qualifiedName, doctype, inputEncoding);
    document.setDocumentURI(systemId);

    try {
        KXmlParser parser = new KXmlParser();
        parser.keepNamespaceAttributes();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware);

        if (source.getByteStream() != null) {
            parser.setInput(source.getByteStream(), inputEncoding);
        } else if (source.getCharacterStream() != null) {
            parser.setInput(source.getCharacterStream());
        } else if (systemId != null) {
            URL url = new URL(systemId);
            URLConnection urlConnection = url.openConnection();
            urlConnection.connect();
            // TODO: if null, extract the inputEncoding from the Content-Type header?
            parser.setInput(urlConnection.getInputStream(), inputEncoding);
        } else {
            throw new SAXParseException(
                    "InputSource needs a stream, reader or URI", null);
        }

        if(parser.nextToken() == XmlPullParser.END_DOCUMENT) {
            throw new SAXParseException(
                    "Unexpected end of document", null);
        }

        parse(parser, document, document, XmlPullParser.END_DOCUMENT);

        parser.require(XmlPullParser.END_DOCUMENT, null, null);
    } catch (XmlPullParserException ex) {
        if(ex.getDetail() instanceof IOException) {
            throw (IOException)ex.getDetail();
        }
        if(ex.getDetail() instanceof RuntimeException) {
            throw (RuntimeException)ex.getDetail();
        }

        LocatorImpl locator = new LocatorImpl();

        locator.setPublicId(source.getPublicId());
        locator.setSystemId(systemId);
        locator.setLineNumber(ex.getLineNumber());
        locator.setColumnNumber(ex.getColumnNumber());

        SAXParseException newEx = new SAXParseException(ex.getMessage(),
                locator);

        if (errorHandler != null) {
            errorHandler.error(newEx);
        }

        throw newEx;
    }

    return document;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:71,代码来源:DocumentBuilderImpl.java


注:本文中的org.kxml2.io.KXmlParser.setFeature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。