本文整理汇总了Java中javax.xml.stream.XMLStreamReader.hasName方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.hasName方法的具体用法?Java XMLStreamReader.hasName怎么用?Java XMLStreamReader.hasName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.hasName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHasNameOnEntityEvent
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* CR 6631264 / sjsxp Issue 45:
* https://sjsxp.dev.java.net/issues/show_bug.cgi?id=45
* XMLStreamReader.hasName() should return false for ENTITY_REFERENCE
*/
@Test
public void testHasNameOnEntityEvent() throws Exception {
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader r = xif.createXMLStreamReader(
this.getClass().getResourceAsStream("ExternalDTD.xml"));
while (r.next() != XMLStreamConstants.ENTITY_REFERENCE) {
System.out.println("event type: " + r.getEventType());
continue;
}
if (r.hasName()) {
System.out.println("hasName returned true on ENTITY_REFERENCE event.");
}
Assert.assertFalse(r.hasName()); // fails
}
示例2: printElementState
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/** Used for debugging xml elements **/
static void printElementState(XMLStreamReader xr) {
StringBuilder sb = new StringBuilder();
sb.append("ElemState: ")
.append(xr.getEventType())
.append("\t")
.append(xr.hasName())
.append("\t")
.append(xr.isStartElement())
.append("\t")
.append(xr.isEndElement())
.append("\t")
.append(xr.isCharacters());
if(xr.hasName()){
sb.append("\t").append(xr.getName());
}
if(xr.hasText()){
sb.append("\t").append(xr.getText());
}
System.out.println(sb.toString());
}
示例3: printName
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
protected static void printName(XMLStreamReader xmlr) {
if (xmlr.hasName()) {
String prefix = xmlr.getPrefix();
String uri = xmlr.getNamespaceURI();
String localName = xmlr.getLocalName();
printName(prefix, uri, localName);
}
}
示例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);
}
}
}