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


Java XMLStreamReader.END_ELEMENT屬性代碼示例

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


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

示例1: readTag

/**
 * 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,代碼行數:30,代碼來源:XmlPullProcessor.java

示例2: readNextTagInsideParent

/**
 * Reads the next tag name from the XML parser so long as it lies within the parent tag name.
 * If the close tag event for the parent is read this method will return null. Otherwise it
 * returns the name of the tag read.
 *
 * @param parentTagName The enclosing tag that forms the limit for the read operation.
 * @return The next tag name or null if there are no more tags to read inside the specified parent.
 */
protected String readNextTagInsideParent(String parentTagName) {
  int event;
  try {
    do {
      event = xmlStreamReader.next();
    } while (event == XMLStreamReader.CHARACTERS ||
             event == XMLStreamReader.COMMENT ||
             event == XMLStreamReader.END_ELEMENT && !xmlStreamReader.getLocalName().equals(parentTagName));
  } catch (Exception e) {
    throw new RuntimeException("Error reading data from the XML pull parser", e);
  }

  if (event == XMLStreamReader.START_ELEMENT) {
    return xmlStreamReader.getLocalName();

  } else if (event == XMLStreamReader.END_ELEMENT) {
    return null;

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

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

示例3: skipToStartRow

/**
 * Skips all rows before the selected starting row.
 *
 * @throws XMLStreamException
 *             If there is an error processing the underlying XML source.
 */
private void skipToStartRow() throws XMLStreamException {
	int rowIndexBeforeFirstRow = sheetMetaData.getFirstRowIndex() - 1;
	boolean skipRows = currentRowIndex < rowIndexBeforeFirstRow;
	while (skipRows && reader.hasNext()) {
		int nextEvent = reader.next();
		if (nextEvent == XMLStreamReader.START_ELEMENT) {
			// If a row was found..
			if (reader.getLocalName().equals(XlsxUtilities.TAG_ROW)) {
				// ... parse the row index (subtract 1 as XLSX indices start with 1)
				parsedRowIndex = Integer
						.parseInt(XlsxUtilities.getAttributes(reader).getValue(XlsxUtilities.TAG_ROW_INDEX)) - 1;

				// Check whether the parsed index is already
				// behind the desired end index (which means that all rows before were
				// empty)
				if (parsedRowIndex > rowIndexBeforeFirstRow) {
					currentRowIndex = rowIndexBeforeFirstRow;
					skipRows = false;
				} else {
					// Update the current row index if parsed index is still
					// before first row to read
					currentRowIndex = parsedRowIndex;
				}
			}
		} else if (nextEvent == XMLStreamReader.END_ELEMENT && reader.getLocalName().equals(XlsxUtilities.TAG_ROW)) {
			// parse until end of row if we haven't parsed too far yet
			skipRows = currentRowIndex < rowIndexBeforeFirstRow;
		}
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:36,代碼來源:XlsxSheetContentParser.java

示例4: skipInitParamElement

private static void skipInitParamElement(XMLStreamReader reader) {
    int state;
    do {
        state = XMLStreamReaderUtil.nextContent(reader);
    } while (state != XMLStreamReader.END_ELEMENT ||
            !reader.getName().equals(QNAME_HANDLER_PARAM));
    XMLStreamReaderUtil.nextElementContent(reader);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:HandlerChainsModel.java

示例5: nextTag

@Override
public int nextTag() throws XMLStreamException {
    int e = next();
    if (e == XMLStreamReader.END_DOCUMENT) return e;
    while (e != XMLStreamReader.END_DOCUMENT) {
        if (e == XMLStreamReader.START_ELEMENT) return e;
        if (e == XMLStreamReader.END_ELEMENT) return e;
        e = next();
    }
    return e;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:XMLReaderComposite.java

示例6: getEventType

@Override
public int getEventType() {
    switch (state) {
    case StartTag: return XMLStreamReader.START_ELEMENT;
    case EndTag: return XMLStreamReader.END_ELEMENT;
    case Payload:
    default:
        return payloadReader.getEventType();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:XMLReaderComposite.java

示例7: getNextSpectrumFromSeekable

private T getNextSpectrumFromSeekable() {
	FromXMLStreamBuilder<T> spectrumBuilder = null;
	try {
		InputStream is = Channels.newInputStream(this.seekable);
		XMLStreamReader xr = XMLInputFactory.newInstance()
			.createXMLStreamReader(is);
		
		while (xr.hasNext()) {
			xr.next();
			
			if (spectrumBuilder != null) {
				spectrumBuilder.accept(xr);
			}

			if(xr.getEventType() == XMLStreamReader.START_ELEMENT){
				if(xr.getLocalName().equals("spectrum")) {
					spectrumBuilder = this.factory.create(this.xml.toString(), xr);
				} else if( xr.getLocalName().equals("referenceableParamGroupRef")) {
					LOGGER.log(Level.WARN, "Random access to spectra will not parse referenceable params");
				}
			} else if(xr.getEventType() == XMLStreamReader.END_ELEMENT) {
				if(xr.getLocalName().equals("spectrum")) {
					return spectrumBuilder.build();
				}					
			}
		}
	} catch (XMLStreamException | FactoryConfigurationError e) {
		LOGGER.log(Level.ERROR, e.toString());
	} 

	return null;
}
 
開發者ID:digitalproteomics,項目名稱:dp-mzml,代碼行數:32,代碼來源:MzMLStAXParser.java

示例8: parseNumberFormats

/**
 * Parses the XLSX styles XML file (with UTF-8 encoding) and returns the parsed number formats.
 *
 * @return the number formats stored within a {@link XlsxNumberFormats} object
 * @throws IOException
 *             in case the Shared Strings Zip entry cannot be opened
 * @throws XMLStreamException
 *             in case the {@link XMLInputFactory} cannot create a {@link XMLStreamReader}
 * @throws XlsxException
 *             in case the shared string XML content is invalid
 */
public XlsxNumberFormats parseNumberFormats() throws XMLStreamException, IOException {

	boolean isCellFormats = false;
	int cellFormatIndex = 0;
	XlsxNumberFormats xlsxNumberFormats = new XlsxNumberFormats();
	XMLStreamReader reader = null;
	try (ZipFile zipFile = new ZipFile(xlsxFile)) {
		ZipEntry zipEntry = zipFile.getEntry(XlsxUtilities.XLSX_PATH_PREFIX + stylesPath);
		if (zipEntry == null) {
			// no styles defined
			return null;
		}

		InputStream inputStream = zipFile.getInputStream(zipEntry);
		reader = xmlFactory.createXMLStreamReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
		while (reader.hasNext()) {
			switch (reader.next()) {
				case XMLStreamReader.START_ELEMENT:
					if (TAG_NUMBER_FORMAT.equals(reader.getLocalName())) {
						Attributes attributes = XlsxUtilities.getAttributes(reader);
						xlsxNumberFormats.addNumberFormat(Integer.parseInt(attributes.getValue(ATT_NUM_FORM_ID)),
								attributes.getValue(ATT_FORMAT_CODE));
					} else if (TAG_CELL_FORMATS.equals(reader.getLocalName())) {
						isCellFormats = true;

						// create an array of the size of all defined cell formats
						xlsxNumberFormats.initializeCellNumberFormatIds(Integer.parseInt(XlsxUtilities.getAttributes(
								reader).getValue(ATT_COUNT)));
					} else if (isCellFormats && TAG_FORMAT.equals(reader.getLocalName())) {
						xlsxNumberFormats.setCellNumberFormatId(cellFormatIndex,
								Integer.parseInt(XlsxUtilities.getAttributes(reader).getValue(ATT_NUMBER_FORMAT_ID)));
						++cellFormatIndex;
					}
					break;
				case XMLStreamReader.END_ELEMENT:
					if (TAG_CELL_FORMATS.equals(reader.getLocalName())) {
						isCellFormats = false;
					}
					break;
				default:
					// ignore other cases
					break;
			}
		}
	} finally {
		if (reader != null) {
			reader.close();
		}
	}
	return xlsxNumberFormats;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:62,代碼來源:XlsxNumberFormatParser.java

示例9: parse

public void parse(InputStream is) {
  try {
    XMLInputFactory2 inputFactory = XMLInputFactory2.class.cast(XMLInputFactory.newInstance());
    XMLStreamReader2 reader =
      XMLStreamReader2.class.cast(inputFactory.createXMLStreamReader(is, "UTF8"));

    List<String> currentRow = null;

    int columnIndex = -1;
    int valueCount = -1;
    int size = 0;
    long startTime = 0;
    StringBuilder currentValue = null;
    while (reader.hasNext()) {
      int type = reader.next();
      switch (type) {
        case XMLStreamReader.START_ELEMENT:
          switch (reader.getLocalName()) {
            case "table_data":
              String tableName = reader.getAttributeValue(null, "name");
              table = replicator.getTable(tableName);
              rows = replicator.getS3Writer().getRowEnqueuer(table, finished);
              startTime = System.currentTimeMillis() / 1000l;
              populateColumnMap();
              break;
            case "field":
              String fieldName = reader.getAttributeValue(null, "name");
              columnIndex = columnMap.getOrDefault(fieldName, new Integer(-1));
              break;
            case "row":
              currentRow = new ArrayList<>();
              for (int i = 0, len = columnMap.size(); i != len; i++) {
                currentRow.add(null);
              }
              rowIndex++;
              valueCount = columnMap.size();
              break;
          }
          break;
        case XMLStreamReader.END_ELEMENT:
          switch (reader.getLocalName()) {
            case "table_data":
              enqueueCurrentRows();
              replicator.getRedshift().recordTableSize(table.name, System.currentTimeMillis() / 1000l - startTime);
              table = null;
              break;
            case "row":
              rows.add(currentRow);
              if (valueCount != 0)
                throw new RuntimeException(
                                            String.format(
                                              "value count was expected to be 0, was instead %s for table %s", valueCount, table.name));
              size += currentRow.stream().mapToInt(v -> v == null ? 4 : v.length()).sum();
              if (size > replicator.getConfig().s3.minimumSegmentSize) {
                enqueueCurrentRows();
                size = 0;
              }
              break;
            case "field":
              if (columnIndex != -1) {
                currentRow.set(columnIndex, currentValue == null ? null : currentValue.toString());
                currentValue = null;
                valueCount--;
                columnIndex = -1;
              }
              break;
          }
          break;
        case XMLStreamReader.CHARACTERS:
          if (columnIndex != -1) {
            if (currentValue == null) currentValue = new StringBuilder();
            currentValue.append(reader.getText());
          }
          break;
      }
    }
    flush();
  } catch (XMLStreamException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:Patreon,項目名稱:euphrates,代碼行數:81,代碼來源:StreamParser.java

示例10: storeElementAndChildrenEx

private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException {
    int depth = 1;
    if (_storeInScopeNamespacesOnElementFragment) {
        storeElementWithInScopeNamespaces(reader);
    } else {
        storeElement(reader);
    }

    while(depth > 0) {
        _eventType = reader.next();
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                depth++;
                storeElement(reader);
                break;
            case XMLStreamReader.END_ELEMENT:
                depth--;
                storeStructure(T_END);
                break;
            case XMLStreamReader.NAMESPACE:
                storeNamespaceAttributes(reader);
                break;
            case XMLStreamReader.ATTRIBUTE:
                storeAttributes(reader);
                break;
            case XMLStreamReader.SPACE:
            case XMLStreamReader.CHARACTERS:
            case XMLStreamReader.CDATA: {
                CharSequence c = reader.getPCDATA();
                if (c instanceof Base64Data) {
                    storeStructure(T_TEXT_AS_OBJECT);
                    //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler
                    storeContentObject(c);
                } else {
                    storeContentCharacters(T_TEXT_AS_CHAR_ARRAY,
                            reader.getTextCharacters(), reader.getTextStart(),
                            reader.getTextLength());
                }
                break;
            }
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
    }

    /*
     * Move to next item after the end of the element
     * that has been stored
     */
    _eventType = reader.next();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:55,代碼來源:StreamReaderBufferCreator.java

示例11: storeElementAndChildrenNoEx

private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException {
    int depth = 1;
    if (_storeInScopeNamespacesOnElementFragment) {
        storeElementWithInScopeNamespaces(reader);
    } else {
        storeElement(reader);
    }

    while(depth > 0) {
        _eventType = reader.next();
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                depth++;
                storeElement(reader);
                break;
            case XMLStreamReader.END_ELEMENT:
                depth--;
                storeStructure(T_END);
                break;
            case XMLStreamReader.NAMESPACE:
                storeNamespaceAttributes(reader);
                break;
            case XMLStreamReader.ATTRIBUTE:
                storeAttributes(reader);
                break;
            case XMLStreamReader.SPACE:
            case XMLStreamReader.CHARACTERS:
            case XMLStreamReader.CDATA: {
                storeContentCharacters(T_TEXT_AS_CHAR_ARRAY,
                        reader.getTextCharacters(), reader.getTextStart(),
                        reader.getTextLength());
                break;
            }
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
    }

    /*
     * Move to next item after the end of the element
     * that has been stored
     */
    _eventType = reader.next();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:48,代碼來源:StreamReaderBufferCreator.java


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