當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLStreamReader.getLocalName方法代碼示例

本文整理匯總了Java中javax.xml.stream.XMLStreamReader.getLocalName方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLStreamReader.getLocalName方法的具體用法?Java XMLStreamReader.getLocalName怎麽用?Java XMLStreamReader.getLocalName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.stream.XMLStreamReader的用法示例。


在下文中一共展示了XMLStreamReader.getLocalName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readTag

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
 * Reads the next tag from the pull parser and throws an exception if its name does not
 * match <var>expectedTagName</var>.
 *
 * @param xmlPullParser The pull parser to read from
 * @param expectedTagName The tag name expected
 */
public static void readTag(XMLStreamReader xmlStreamReader, String expectedTagName) {
  // Look for any start tag event
  int event;
  try {
    do {
      event = xmlStreamReader.next();
    } while (event == XMLStreamReader.CHARACTERS || event == XMLStreamReader.END_ELEMENT || event == XMLStreamReader.COMMENT);
  } catch (Exception e) {
    throw new RuntimeException("Error reading data from the XML pull parser", e);
  }

  if (event == XMLStreamReader.START_ELEMENT) {
    if (!expectedTagName.equals(xmlStreamReader.getLocalName())) {
      throw new IllegalArgumentException("Expected tag [" + expectedTagName + "] but got [" + xmlStreamReader.getLocalName() + "]");
    }

  } else if (event == XMLStreamReader.END_DOCUMENT) {
    throw new IllegalStateException("Unexpected end of document while looking for tag [" + expectedTagName + "]");

  } else {
    throw new IllegalStateException("Expecting a tag but found [" + event + "]");
  }
}
 
開發者ID:alfasoftware,項目名稱:morf,代碼行數:31,代碼來源:XmlPullProcessor.java

示例2: testStartElement

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
@Test
public void testStartElement() {
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        XMLStreamReader xsr = xif.createXMLStreamReader(this.getClass().getResource(INPUT_FILE).toExternalForm(),
                this.getClass().getResourceAsStream(INPUT_FILE));

        while (xsr.hasNext()) {
            int event = xsr.next();
            if (event == XMLStreamReader.START_ELEMENT) {
                String localName = xsr.getLocalName();
                boolean print = "para".equals(localName);
                int nrOfAttr = xsr.getAttributeCount();
                if (print) {
                    Assert.assertTrue(nrOfAttr > 0, "Default attribute declared in DTD is missing");
                }

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:Bug6370703.java

示例3: fromXml

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static TsoOvervoltageSecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    String text = null;
    boolean computationSucceed = true;
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;
            case XMLEvent.END_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case "computation-succeed":
                        computationSucceed = Boolean.parseBoolean(text);
                        break;

                    case "overvoltage-count":
                        return new TsoOvervoltageSecurityIndex(contingencyId, Integer.parseInt(text), computationSucceed);

                    default:
                        break;
                }
                break;

            default:
                break;
        }
    }
    throw new AssertionError("overvoltage-count element not found");
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:30,代碼來源:TsoOvervoltageSecurityIndex.java

示例4: handleStartElement

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
private void handleStartElement(XMLStreamReader xmlr) {
    output += "<";
    output += xmlr.getLocalName();
    if (xmlr.hasText())
        output += xmlr.getText();
    printAttributes(xmlr);
    output += ">";
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:EntityTest.java

示例5: getSheetId

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
 * Helper method to read the "workbook.xml" in the document and find out the sheet id for
 * given sheet name, or the first sheet if sheetName is null or empty.
 * @param workbook InputStream of the workbook. Caller is responsible for closing it.
 * @param sheetName Sheet name to lookup.
 * @return Non-null value if found a sheet with given name. Otherwise null
 * @throws XMLStreamException
 */
public static String getSheetId(final InputStream workbook, final String sheetName) throws XMLStreamException {
  checkNotNull(workbook);

  final XMLStreamReader wbReader  = XML_INPUT_FACTORY.createXMLStreamReader(workbook);
  final boolean retrieveFirstSheet = sheetName == null || sheetName.isEmpty();

  while (wbReader.hasNext()) {
    wbReader.next();
    final int event = wbReader.getEventType();
    switch (event) {
      case START_ELEMENT: {
        final String name = wbReader.getLocalName();
        if (SHEET.equals(name)) {
          String sheet = wbReader.getAttributeValue(/*namespaceURI=*/null, SHEET_NAME);
          // Sheet names are case insensitive
          if (retrieveFirstSheet || sheetName.equalsIgnoreCase(sheet)) {
            return wbReader.getAttributeValue(SHEET_ID_NS, SHEET_ID);
          }
        }
        break;
      }
    }
  }

  return null;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:35,代碼來源:ExcelUtil.java

示例6: fromXml

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static TsoUndervoltageSecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    String text = null;
    boolean computationSucceed = true;
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;
            case XMLEvent.END_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case "computation-succeed":
                        computationSucceed = Boolean.parseBoolean(text);
                        break;

                    case "undervoltage-count":
                        return new TsoUndervoltageSecurityIndex(contingencyId, Integer.parseInt(text), computationSucceed);

                    default:
                        break;
                }
                break;

            default:
                break;
        }
    }
    throw new AssertionError("undervoltage-count element not found");
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:30,代碼來源:TsoUndervoltageSecurityIndex.java

示例7: fromXml

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static TsoDisconnectedGenerator fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    String text = null;
    Map<String, Float> disconnectedGenerators = new HashMap<>();
    String id = null;
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;

            case XMLEvent.START_ELEMENT:
                if ("generator".equals(xmlsr.getLocalName())) {
                    id = xmlsr.getAttributeValue(null, "id");
                }
                break;

            case XMLEvent.END_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case "generator":
                        if (id == null) {
                            throw new AssertionError();
                        }
                        float p = Float.parseFloat(text);
                        disconnectedGenerators.put(id, p);
                        id = null;
                        break;
                    case "index":
                        return new TsoDisconnectedGenerator(contingencyId, disconnectedGenerators);
                    default:
                        throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                }
                break;

            default:
                break;
        }
    }
    throw new AssertionError("Should not happen");
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:41,代碼來源:TsoDisconnectedGenerator.java

示例8: readGraph

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
private void readGraph(XMLStreamReader reader) throws XMLStreamException {
    while (reader.hasNext()) {
        int eventType = reader.next();
        if (eventType != XMLEvent.START_ELEMENT) {
            continue;
        }

        String elementName = reader.getLocalName();
        if (elementName.equals("node")) {
            readNodeElement(reader);
        } else if (elementName.equals("way")) {
            readWayElement(reader);
        }
    }
}
 
開發者ID:rovaniemi,項目名稱:osm-graph-parser,代碼行數:16,代碼來源:StreamingXmlGraphParser.java

示例9: failWithLocalName

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
private static void failWithLocalName(String key,
        XMLStreamReader reader, String arg) {
    throw new UtilException(key,
        Integer.toString(reader.getLocation().getLineNumber()),
        reader.getLocalName(),
        arg );
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:HandlerChainsModel.java

示例10: verifyTag

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static void verifyTag(XMLStreamReader reader, String namespaceURI, String localName) {
    if (!localName.equals(reader.getLocalName()) || !namespaceURI.equals(reader.getNamespaceURI())) {
        throw new XMLStreamReaderException(
            "xmlreader.unexpectedState.tag",
                "{" + namespaceURI + "}" + localName,
                "{" + reader.getNamespaceURI() + "}" + reader.getLocalName());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:XMLStreamReaderUtil.java

示例11: 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

示例12: readXML

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
private void readXML(byte[] xmlData, String expectedContent)
        throws Exception {
    InputStream stream = new ByteArrayInputStream(xmlData);
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader xmlReader
            = factory.createXMLStreamReader(stream);
    boolean inTestElement = false;
    StringBuilder sb = new StringBuilder();
    while (xmlReader.hasNext()) {
        String ename;
        switch (xmlReader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT:
                ename = xmlReader.getLocalName();
                if (ename.equals("writeCharactersWithString")
                        || ename.equals("writeCharactersWithArray")) {
                    inTestElement = true;
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                ename = xmlReader.getLocalName();
                if (ename.equals("writeCharactersWithString")
                        || ename.equals("writeCharactersWithArray")) {
                    inTestElement = false;
                    String content = sb.toString();
                    System.out.println(ename + " text:'" + content + "' expected:'" + expectedContent+"'");
                    Assert.assertEquals(content, expectedContent);
                    sb.setLength(0);
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                if (inTestElement) {
                    sb.append(xmlReader.getText());
                }
                break;
        }
        xmlReader.next();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:39,代碼來源:SurrogatesTest.java

示例13: fromXml

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static MultiCriteriaVoltageStabilityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    String text = null;
    Map<String, Float> lockedTapChangerLoads = new LinkedHashMap<>();
    Map<String, Float> stoppedTapChangerLoads = new LinkedHashMap<>();
    Map<String, Float> underVoltageAutomatonGenerators = new LinkedHashMap<>();
    Set<String> underVoltageBuses = new LinkedHashSet<>();
    String id = null;
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;
            case XMLEvent.START_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case TAG_LOCKED_TAP_CHANGER_LOAD:
                    case TAG_STOPPED_TAP_CHANGER_LOAD:
                    case TAG_UNDER_VOLTAGE_AUTOMATON_GENERATOR:
                        id = xmlsr.getAttributeValue(null, TAG_ID);
                        break;
                    case TAG_UNDER_BUS_VOLTAGE:
                    case TAG_INDEX:
                        // nothing to do
                        break;
                    default:
                        throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                }
                break;

            case XMLEvent.END_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case TAG_LOCKED_TAP_CHANGER_LOAD:
                        if (id == null) {
                            throw new AssertionError();
                        }
                        lockedTapChangerLoads.put(id, Float.parseFloat(text));
                        id = null;
                        break;
                    case TAG_STOPPED_TAP_CHANGER_LOAD:
                        if (id == null) {
                            throw new AssertionError();
                        }
                        stoppedTapChangerLoads.put(id, Float.parseFloat(text));
                        id = null;
                        break;
                    case TAG_UNDER_VOLTAGE_AUTOMATON_GENERATOR:
                        if (id == null) {
                            throw new AssertionError();
                        }
                        underVoltageAutomatonGenerators.put(id, Float.parseFloat(text));
                        id = null;
                        break;
                    case TAG_UNDER_BUS_VOLTAGE:
                        underVoltageBuses.add(text);
                        break;
                    case TAG_INDEX:
                        return new MultiCriteriaVoltageStabilityIndex(contingencyId, lockedTapChangerLoads, stoppedTapChangerLoads,
                                                                      underVoltageAutomatonGenerators, underVoltageBuses);
                    default:
                        throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                }
                break;

            default:
                break;
        }
    }
    throw new AssertionError("Should not happen");
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:70,代碼來源:MultiCriteriaVoltageStabilityIndex.java

示例14: fromXml

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static List<SecurityIndex> fromXml(String contingencyId, Reader reader) {
    List<SecurityIndex> indexes = new ArrayList<>();
    try {
        XMLStreamReader xmlsr = XML_INPUT_FACTORY_SUPPLIER.get().createXMLStreamReader(reader);
        while (xmlsr.hasNext()) {
            int eventType = xmlsr.next();
            switch (eventType) {
                case XMLEvent.START_ELEMENT:
                    switch (xmlsr.getLocalName()) {
                        case "index":
                            switch (xmlsr.getAttributeValue(null, "name")) {
                                case OverloadSecurityIndex.XML_NAME:
                                    indexes.add(OverloadSecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case UnderOverVoltageSecurityIndex.XML_NAME:
                                    indexes.add(UnderOverVoltageSecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case SmallSignalSecurityIndex.XML_NAME:
                                    indexes.add(SmallSignalSecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case TransientSecurityIndex.XML_NAME:
                                    indexes.add(TransientSecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case TsoOverloadSecurityIndex.XML_NAME:
                                    indexes.add(TsoOverloadSecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case TsoOvervoltageSecurityIndex.XML_NAME:
                                    indexes.add(TsoOvervoltageSecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case TsoUndervoltageSecurityIndex.XML_NAME:
                                    indexes.add(TsoUndervoltageSecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case TsoFrequencySecurityIndex.XML_NAME:
                                    indexes.add(TsoFrequencySecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case TsoSynchroLossSecurityIndex.XML_NAME:
                                    indexes.add(TsoSynchroLossSecurityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case TsoGeneratorVoltageAutomaton.XML_NAME:
                                    indexes.add(TsoGeneratorVoltageAutomaton.fromXml(contingencyId, xmlsr));
                                    break;
                                case TsoGeneratorSpeedAutomaton.XML_NAME:
                                    indexes.add(TsoGeneratorSpeedAutomaton.fromXml(contingencyId, xmlsr));
                                    break;
                                case TsoDisconnectedGenerator.XML_NAME:
                                    indexes.add(TsoDisconnectedGenerator.fromXml(contingencyId, xmlsr));
                                    break;
                                case MultiCriteriaVoltageStabilityIndex.XML_NAME:
                                    indexes.add(MultiCriteriaVoltageStabilityIndex.fromXml(contingencyId, xmlsr));
                                    break;
                                case MultiCriteriaVoltageStabilityIndex2.XML_NAME:
                                    indexes.add(MultiCriteriaVoltageStabilityIndex2.fromXml(contingencyId, xmlsr));
                                    break;
                                default:
                                    throw new AssertionError("Unexpected attribute value: " + xmlsr.getAttributeValue(null, "name"));
                            }
                            break;

                        default:
                            throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                    }
                    break;

                default:
                    break;
            }
        }
    } catch (XMLStreamException e) {
        throw new UncheckedXmlStreamException(e);
    }
    return indexes;
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:73,代碼來源:SecurityIndexParser.java

示例15: fromXml

import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static TsoGeneratorVoltageAutomaton fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    LimitsXmlParsingState state = null;
    String text = null;
    List<String> onUnderVoltageDiconnectedGenerators = new ArrayList<>();
    List<String> onOverVoltageDiconnectedGenerators = new ArrayList<>();
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;

            case XMLEvent.START_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case ON_UNDER_VOLTAGE_DISCONNECTED_GENERATORS:
                        state = LimitsXmlParsingState.UNDER;
                        break;

                    case ON_OVER_VOLTAGE_DISCONNECTED_GENERATORS:
                        state = LimitsXmlParsingState.OVER;
                        break;

                    case GEN:
                    case INDEX:
                        // nothing to do
                        break;

                    default:
                        throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                }
                break;

            case XMLEvent.END_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case ON_UNDER_VOLTAGE_DISCONNECTED_GENERATORS:
                    case ON_OVER_VOLTAGE_DISCONNECTED_GENERATORS:
                        state = null;
                        break;

                    case GEN:
                        LimitsXmlParsingState.addGenerator(state, text, onUnderVoltageDiconnectedGenerators, onOverVoltageDiconnectedGenerators);
                        break;

                    case INDEX:
                        return new TsoGeneratorVoltageAutomaton(contingencyId, onUnderVoltageDiconnectedGenerators, onOverVoltageDiconnectedGenerators);

                    default:
                        throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                }
                break;

            default:
                break;
        }
    }
    throw new AssertionError("Should not happen");
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:58,代碼來源:TsoGeneratorVoltageAutomaton.java


注:本文中的javax.xml.stream.XMLStreamReader.getLocalName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。