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


Java XMLStreamReader.hasName方法代码示例

本文整理汇总了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
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:StreamReaderTest.java

示例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());
}
 
开发者ID:digitalproteomics,项目名称:dp-mzml,代码行数:24,代码来源:MzMLStAXParser.java

示例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);
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:9,代码来源:XMLStreamHelper.java

示例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);
    }
  }
}
 
开发者ID:unix-junkie,项目名称:teamcity-autotools-plugin,代码行数:69,代码来源:DejagnuTestsXMLParser.java


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