本文整理汇总了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();
}
}
示例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;
}
示例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;
}
示例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;
}