当前位置: 首页>>代码示例>>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;未经允许,请勿转载。