本文整理汇总了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 + "]");
}
}
示例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());
}
}
示例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");
}
示例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 += ">";
}
示例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;
}
示例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");
}
示例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");
}
示例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);
}
}
}
示例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 );
}
示例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());
}
}
示例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);
}
}
示例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();
}
}
示例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");
}
示例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;
}
示例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");
}