本文整理匯總了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);
}
}
}