當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。