本文整理汇总了Java中javax.xml.stream.XMLStreamReader.isStartElement方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.isStartElement方法的具体用法?Java XMLStreamReader.isStartElement怎么用?Java XMLStreamReader.isStartElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.isStartElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetAttributeValueWithNs
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private void testGetAttributeValueWithNs(String nameSpace, String attrName, Consumer<String> checker) throws Exception {
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(new FileInputStream(testFile));
while (xsr.hasNext()) {
xsr.next();
if (xsr.isStartElement()) {
String v;
v = xsr.getAttributeValue(nameSpace, attrName);
checker.accept(v);
}
}
}
示例2: readExternalFile
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private boolean readExternalFile(final String fileUrl) {
InputStream ios = null;
XMLStreamReader reader = null;
try {
final URL xmlURL = new URL(fileUrl);
ios = xmlURL.openStream();
reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
while (reader.hasNext()) {
if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
}
reader.next();
}
return true;
} catch (IOException ioe) {
return false;
} catch (XMLStreamException xmlse) {
return false;
} finally {
PolicyUtils.IO.closeResource(reader);
PolicyUtils.IO.closeResource(ios);
}
}
示例3: parse
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* Method for parsing orders XML.
* @param is input stream for parsing.
* @return SortedMap of OrderBook's mapping key name.
* @throws FileNotFoundException if there is no such file.
* @throws XMLStreamException The base exception for unexpected processing errors. This Exception
* class is used to report well-formedness errors as well as unexpected
* processing conditions.
*/
public SortedMap<String, OrderBook> parse(InputStream is) throws FileNotFoundException, XMLStreamException {
SortedMap<String, OrderBook> orders = new TreeMap<>(String::compareTo);
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader = factory.createXMLStreamReader(is);
OrderBook orderBook;
String book;
reader.next();
while (reader.hasNext()) {
if (reader.next() == XMLStreamConstants.START_ELEMENT) {
if (reader.isStartElement()) {
book = reader.getAttributeValue(null, "book");
if ("AddOrder".equals(reader.getLocalName())) {
if (!orders.containsKey(book)) {
orderBook = new OrderBook(book);
orders.put(book, orderBook);
} else {
orderBook = orders.get(book);
}
orderBook.addOrder(OrderBook.OPERATION.valueOf(reader.getAttributeValue(null, "operation")),
Integer.parseInt(reader.getAttributeValue(null, "orderId")),
Integer.parseInt(reader.getAttributeValue(null, "volume")),
Float.parseFloat(reader.getAttributeValue(null, "price")));
} else {
orders.get(book).delOrder(Integer.parseInt(reader.getAttributeValue(null, "orderId")));
}
}
}
}
return orders;
}
示例4: parseXmlTestResults
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* Parses Xml file entry and public test results.
* @param xmlEntry Xml file entry
* @param testSuiteName name of test suite
*/
private void parseXmlTestResults(@NotNull final String xmlEntry, @NotNull final String testSuiteName){
Boolean isTestXml = false;
try {
final XMLInputFactory f = XMLInputFactory.newInstance();
final XMLStreamReader reader = f.createXMLStreamReader(new StringReader(xmlEntry));
String testResult = null;
String testName = null;
String tempTag = "";
String testOutput = "";
while (reader.hasNext()){
if (!isTestXml && reader.hasName()){
if (!reader.getLocalName().equalsIgnoreCase("testsuite")){
break;
}
isTestXml = true;
if (myTestsReporter != null) {
myTestsReporter.publicTestSuiteStarted(testSuiteName);
}
}
if (reader.isStartElement() && reader.hasName() && reader.getLocalName().equalsIgnoreCase("test")){
testResult = null;
testName = null;
}
if (reader.isEndElement() && reader.hasName() && reader.getLocalName().equalsIgnoreCase("test")){
myTestsCount += testResult != null && testName != null ? 1 : 0;
if (myTestsReporter != null && testResult != null && testName != null){
myTestsReporter.publicTestCaseInfo(testName, testResult, testOutput);
}
}
if (reader.hasName()){
tempTag = reader.getLocalName();
}
if (reader.hasText()){
if (tempTag.equalsIgnoreCase("result")){
testResult = reader.getText();
}
else {
if (tempTag.equalsIgnoreCase("name")) {
testName = reader.getText();
} else if (tempTag.equalsIgnoreCase("output")) {
testOutput = reader.getText();
}
}
}
reader.next();
}
reader.close();
} catch (final XMLStreamException e) {
myTestsCount = 0;
if (myTestsReporter != null) {
myTestsReporter.reportWarning("DejagnuTestsXMLParser:" + e.getMessage());
}
else{
System.out.println("DejagnuTestsXMLParser: " + e.getMessage());
}
}
finally {
if (isTestXml && myTestsReporter != null){
myTestsReporter.publicTestSuiteFinished(testSuiteName);
}
}
}