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


Java KXmlParser.require方法代码示例

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


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

示例1: processSurveyList

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public void processSurveyList(KXmlParser parser, Hashtable formInfo) throws XmlPullParserException{
    try {
        //boolean inItem = false;
        parser.nextTag();
        parser.require(XmlPullParser.START_TAG, null, "forms");
        while( parser.nextTag() != XmlPullParser.END_TAG ){
            //parser file names
            parser.require(XmlPullParser.START_TAG, null, null);

            String name = parser.getName();
            String url = parser.getAttributeValue(null, "url");
            String text = parser.nextText();

            if(name.equals("form"))
                {
                //inItem = true;
                //items.addElement(text);
                formInfo.put(text, url);
                }
            else
                //inItem = false;

            parser.require(XmlPullParser.END_TAG, null, "form");
        }
        parser.require(XmlPullParser.END_TAG, null, "forms");

        parser.next();
        parser.require(XmlPullParser.END_DOCUMENT, null, null);

    } catch (IOException e) {
        // TODO: handle exception
        System.out.println("XML parser error");
        e.printStackTrace();

    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:37,代码来源:DisplayFormsHttpState.java

示例2: readTestSuite

import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
private Collection<Outcome> readTestSuite(KXmlParser parser)
        throws XmlPullParserException, IOException {
    Collection<Outcome> outcomes = new ArrayList<Outcome>();

    parser.nextTag();
    parser.require(XmlPullParser.START_TAG, null, XmlReportConstants.TESTSUITE);
    Map<String, String> testSuiteAttributes = createAttributeMap(parser);
    String timestamp = testSuiteAttributes.get(XmlReportConstants.TIMESTAMP);

    parser.nextTag();
    parser.require(XmlPullParser.START_TAG, null, XmlReportConstants.PROPERTIES);
    parser.nextTag();
    parser.require(XmlPullParser.END_TAG, null, XmlReportConstants.PROPERTIES);
    while (parser.nextTag() == XmlPullParser.START_TAG) {
        parser.require(XmlPullParser.START_TAG, null, XmlReportConstants.TESTCASE);

        Map<String, String> testCaseAttributes = createAttributeMap(parser);
        String name = testCaseAttributes.get(XmlReportConstants.ATTR_NAME);
        String classname = testCaseAttributes.get(XmlReportConstants.ATTR_CLASSNAME);

        Result result = Result.SUCCESS;
        String resultOutput = null;
        parser.nextTag();
        String tagName = parser.getName();
        if (resultTagNames.contains(tagName)) {
            parser.require(XmlPullParser.START_TAG, null, tagName);

            Map<String, String> resultAttributes = createAttributeMap(parser);
            String type = resultAttributes.get(XmlReportConstants.ATTR_TYPE);
            result = Result.valueOf(type);

            resultOutput = parser.nextText();

            parser.require(XmlPullParser.END_TAG, null, tagName);
            parser.nextTag();
        }

        // create outcome!
        SimpleDateFormat dateFormat = new SimpleDateFormat(XmlReportConstants.DATEFORMAT);
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        dateFormat.setLenient(true);
        Date date;
        try {
            date = dateFormat.parse(timestamp);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        outcomes.add(new Outcome(classname + "#" + name, result, resultOutput, date));

        parser.require(XmlPullParser.END_TAG, null, XmlReportConstants.TESTCASE);
    }
    parser.require(XmlPullParser.END_TAG, null, XmlReportConstants.TESTSUITE);

    return outcomes;
}
 
开发者ID:dryganets,项目名称:vogar,代码行数:56,代码来源:XmlReportReader.java

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

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