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


Java KXmlParser.keepNamespaceAttributes方法代码示例

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


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

示例1: 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

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