gpt4 book ai didi

javolution.xml.stream.XMLStreamReader类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 15:18:40 26 4
gpt4 key购买 nike

本文整理了Java中javolution.xml.stream.XMLStreamReader类的一些代码示例,展示了XMLStreamReader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLStreamReader类的具体详情如下:
包路径:javolution.xml.stream.XMLStreamReader
类名称:XMLStreamReader

XMLStreamReader介绍

[英]This interface is similar to javax.xml.stream.XMLStreamReader; but it does not forces dynamic allocation when parsing (its methods returns CharArray instances instead of String).

Except for the speed (faster) and its real-time characteristics the usage/behavior is about the same as its StAX counterpart.

The CharArray instances returned by this reader supports fast primitive conversions as illustrated below. [code] // Creates a new reader (potentially recycled). XMLInputFactory factory = OSGiServices.getXMLInputFactory(); XMLStreamReader reader = factory.createXMLStreamReader(inputStream); while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: if (reader.getLocalName().equals("Time")) { // Reads primitive types (int) attributes directly (no memory allocation). time.hour = reader.getAttributeValue(null, "hour").toInt(); time.minute = reader.getAttributeValue(null, "minute").toInt(); time.second = reader.getAttributeValue(null, "second").toInt(); } ... break; } } reader.close(); // Close the reader (does not close underlying input stream). [/code]
[中]这个界面类似于javax.xml.stream.XMLStreamReader;但它在解析时不强制动态分配(它的方法返回CharArray实例而不是String)。
除了速度(更快)及其实时性特征外,使用/行为与StAX差不多。
该读取器返回的CharArray实例支持如下所示的快速原语转换。[code]//创建一个新的读卡器(可能回收)。XMLInputFactory工厂=OSGiServices。getXMLInputFactory();XMLStreamReader=工厂。createXMLStreamReader(inputStream);while(reader.getEventType()!=XMLStreamConstants。END_DOCUMENT){switch(reader.next()){case XMLStreamConstants.START_元素:if(reader.getLocalName().equals(“Time”){//直接读取基本类型(int)属性(无内存分配)。Time.hour=reader.getAttributeValue(null,“hour”).toInt();Time.minute=reader.getAttributeValue(null,“minute”).toInt(); 时间第二个=读卡器。getAttributeValue(空,“秒”)。toInt();}。。。中断;}读者close();//关闭读卡器(不关闭底层输入流)。[code]

代码示例

代码示例来源:origin: javolution/javolution

while (xml.hasNext()) {
  switch (xml.next()) {
  case XMLStreamReader.START_DOCUMENT:
    System.out.println("Start Document");
    break;
  case XMLStreamReader.START_ELEMENT:
    System.out.println("Start Element: " + xml.getLocalName() + "("
        + xml.getNamespaceURI() + ")");
    for (int i = 0, n = xml.getAttributeCount(); i < n; i++) {
      System.out.println("   Attribute: "
          + xml.getAttributeLocalName(i) + "("
          + xml.getAttributeNamespace(i) + "), Value: "
          + xml.getAttributeValue(i));
    if (xml.getLocalName().equals("Body")
        && xml.getNamespaceURI().equals(ENVELOPE_URI))
      return; // End body.
    System.out.println("End Element: " + xml.getLocalName() + "("
        + xml.getNamespaceURI() + ")");
    break;
  case XMLStreamReader.CHARACTERS:
    System.out.println("Characters: " + xml.getText());
    break;
  case XMLStreamReader.CDATA:
    System.out.println("CDATA: " + xml.getText());
    break;
  case XMLStreamReader.COMMENT:
    System.out.println("Comment: " + xml.getText());

代码示例来源:origin: io.github.msdk/msdk-io-mzml

/**
 * <p>
 * Gets the required attribute from xmlStreamReader, throws an exception if the attribute is not
 * found
 * </p>
 *
 * @param xmlStreamReader XMLStreamReader instance used to parse
 * @param attr Attribute's value to be found
 * @return a CharArray containing the value of the attribute.
 */
public CharArray getRequiredAttribute(XMLStreamReader xmlStreamReader, String attr) {
 CharArray attrValue = xmlStreamReader.getAttributeValue(null, attr);
 if (attrValue == null)
  throw new IllegalStateException("Tag " + xmlStreamReader.getLocalName() + " must provide an `"
    + attr + "`attribute (Line " + xmlStreamReader.getLocation().getLineNumber() + ")");
 return attrValue;
}

代码示例来源:origin: org.javolution/javolution-core-java

throw new XMLStreamException(
        "Binding has no class attribute defined, cannot retrieve class");
  classQName = QName.valueOf(reader.getAttributeValue(
      _classAttribute.getNamespaceURI(),
      _classAttribute.getLocalName()));
        "Cannot retrieve class (class attribute not found)");
} else {
  classQName = QName.valueOf(reader.getNamespaceURI(),
      reader.getLocalName());

代码示例来源:origin: org.javolution/javolution-core-java

while (xmlIn.hasNext()) {
  if ((xmlIn.next() == XMLStreamReader.START_ELEMENT)
      && xmlIn.getLocalName().equals("Body")
      && xmlIn.getNamespaceURI().equals(ENVELOPE_URI)) {
    xmlIn.next();
    readResponse(_reader);
    break;

代码示例来源:origin: org.mobicents.protocols.ss7.map/map-impl

@Override
public void read(javolution.xml.XMLFormat.InputElement xml, ArrayListSerializingBase data) throws XMLStreamException {
  data.data.clear();
  while (xml.hasNext()) {
    String localName = xml.getStreamReader().getLocalName().toString();
    if (localName.equals(data.elementName)) {
      data.data.add(xml.get(data.elementName, data.classDef));
    } else
      throw new XMLStreamException("Only <" + data.elementName + "> elements are allowed in this list. Found: " + localName);
  }
}

代码示例来源:origin: io.github.msdk/msdk-io-mzml

/**
 * <p>
 * Call this method when the <code>xmlStreamReader</code> enters <code>&lt;cvParam&gt;</code> tag
 * </p>
 * 
 * @param xmlStreamReader an instance of {@link javolution.xml.internal.stream.XMLStreamReaderImpl
 * XMLStreamReaderImpl
 * @return {@link io.github.msdk.io.mzml.data.MzMLCVParam MzMLCVParam} object notation of the
 *         <code>&lt;cvParam&gt;</code> entered
 */
private MzMLCVParam createMzMLCVParam(XMLStreamReader xmlStreamReader) {
 CharArray accession = xmlStreamReader.getAttributeValue(null, MzMLTags.ATTR_ACCESSION);
 CharArray value = xmlStreamReader.getAttributeValue(null, MzMLTags.ATTR_VALUE);
 CharArray name = xmlStreamReader.getAttributeValue(null, MzMLTags.ATTR_NAME);
 CharArray unitAccession = xmlStreamReader.getAttributeValue(null, MzMLTags.ATTR_UNIT_ACCESSION);
 // accession is a required attribute
 if (accession == null) {
  throw new IllegalStateException("Any cvParam must have an accession.");
 }
 // these attributes are optional
 String valueStr = value == null ? null : value.toString();
 String nameStr = name == null ? null : name.toString();
 String unitAccessionStr = unitAccession == null ? null : unitAccession.toString();
 return new MzMLCVParam(accession.toString(), valueStr, nameStr, unitAccessionStr);
}

代码示例来源:origin: javolution/javolution

throw new XMLStreamException(
        "Binding has no class attribute defined, cannot retrieve class");
  classQName = QName.valueOf(reader.getAttributeValue(_classAttribute
      .getNamespaceURI(), _classAttribute.getLocalName()));
  if (classQName == null)
        "Cannot retrieve class (class attribute not found)");
} else {
  classQName = QName.valueOf(reader.getNamespaceURI(), reader
      .getLocalName());

代码示例来源:origin: javolution/javolution

while (xmlIn.hasNext()) {
  if ((xmlIn.next() == XMLStreamReader.START_ELEMENT)
      && xmlIn.getLocalName().equals("Body")
      && xmlIn.getNamespaceURI().equals(ENVELOPE_URI)) {
    xmlIn.next();
    readResponse(_reader);
    break;

代码示例来源:origin: org.restcomm.protocols.ss7.map/map-impl

@Override
public void read(javolution.xml.XMLFormat.InputElement xml, ArrayListSerializingBase data) throws XMLStreamException {
  data.data.clear();
  while (xml.hasNext()) {
    String localName = xml.getStreamReader().getLocalName().toString();
    if (localName.equals(data.elementName)) {
      data.data.add(xml.get(data.elementName, data.classDef));
    } else
      throw new XMLStreamException("Only <" + data.elementName + "> elements are allowed in this list. Found: " + localName);
  }
}

代码示例来源:origin: msdk/msdk

/**
 * <p>
 * Call this method when the <code>xmlStreamReader</code> enters <code>&lt;cvParam&gt;</code> tag
 * </p>
 * 
 * @param xmlStreamReader an instance of {@link javolution.xml.internal.stream.XMLStreamReaderImpl
 * XMLStreamReaderImpl
 * @return {@link io.github.msdk.io.mzml.data.MzMLCVParam MzMLCVParam} object notation of the
 *         <code>&lt;cvParam&gt;</code> entered
 */
private MzMLCVParam createMzMLCVParam(XMLStreamReader xmlStreamReader) {
 CharArray accession = xmlStreamReader.getAttributeValue(null, MzMLTags.ATTR_ACCESSION);
 CharArray value = xmlStreamReader.getAttributeValue(null, MzMLTags.ATTR_VALUE);
 CharArray name = xmlStreamReader.getAttributeValue(null, MzMLTags.ATTR_NAME);
 CharArray unitAccession = xmlStreamReader.getAttributeValue(null, MzMLTags.ATTR_UNIT_ACCESSION);
 // accession is a required attribute
 if (accession == null) {
  throw new IllegalStateException("Any cvParam must have an accession.");
 }
 // these attributes are optional
 String valueStr = value == null ? null : value.toString();
 String nameStr = name == null ? null : name.toString();
 String unitAccessionStr = unitAccession == null ? null : unitAccession.toString();
 return new MzMLCVParam(accession.toString(), valueStr, nameStr, unitAccessionStr);
}

代码示例来源:origin: org.javolution/javolution-core-java

while (xml.hasNext()) {
  switch (xml.next()) {
    case XMLStreamReader.START_DOCUMENT:
      System.out.println("Start Document");
      break;
    case XMLStreamReader.START_ELEMENT:
      System.out.println("Start Element: " + xml.getLocalName()
          + "(" + xml.getNamespaceURI() + ")");
      for (int i = 0, n = xml.getAttributeCount(); i < n; i++) {
        System.out.println("   Attribute: "
            + xml.getAttributeLocalName(i) + "("
            + xml.getAttributeNamespace(i) + "), Value: "
            + xml.getAttributeValue(i));
      if (xml.getLocalName().equals("Body")
          && xml.getNamespaceURI().equals(ENVELOPE_URI))
        return; // End body.
      System.out.println("End Element: " + xml.getLocalName()
          + "(" + xml.getNamespaceURI() + ")");
      break;
    case XMLStreamReader.CHARACTERS:
      System.out.println("Characters: " + xml.getText());
      break;
    case XMLStreamReader.CDATA:
      System.out.println("CDATA: " + xml.getText());
      break;
    case XMLStreamReader.COMMENT:
      System.out.println("Comment: " + xml.getText());

代码示例来源:origin: io.github.msdk/msdk-io-mzxml

/**
 * <p>
 * Gets the required attribute from xmlStreamReader, throws an exception of the attribute is not
 * found
 * </p>
 *
 * @return a CharArray containing the value of the attribute.
 * @param xmlStreamReader a {@link javolution.xml.stream.XMLStreamReader} object.
 * @param attr a {@link java.lang.String} object.
 */
public CharArray getRequiredAttribute(XMLStreamReader xmlStreamReader, String attr) {
 CharArray attrValue = xmlStreamReader.getAttributeValue(null, attr);
 if (attrValue == null)
  throw new IllegalStateException("Tag " + xmlStreamReader.getLocalName() + " must provide an `"
    + attr + "`attribute (Line " + xmlStreamReader.getLocation().getLineNumber() + ")");
 return attrValue;
}

代码示例来源:origin: msdk/msdk

/**
 * <p>
 * Gets the required attribute from xmlStreamReader, throws an exception if the attribute is not
 * found
 * </p>
 *
 * @param xmlStreamReader XMLStreamReader instance used to parse
 * @param attr Attribute's value to be found
 * @return a CharArray containing the value of the attribute.
 */
public CharArray getRequiredAttribute(XMLStreamReader xmlStreamReader, String attr) {
 CharArray attrValue = xmlStreamReader.getAttributeValue(null, attr);
 if (attrValue == null)
  throw new IllegalStateException("Tag " + xmlStreamReader.getLocalName() + " must provide an `"
    + attr + "`attribute (Line " + xmlStreamReader.getLocation().getLineNumber() + ")");
 return attrValue;
}

代码示例来源:origin: msdk/msdk

/**
 * <p>
 * Gets the required attribute from xmlStreamReader, throws an exception of the attribute is not
 * found
 * </p>
 *
 * @return a CharArray containing the value of the attribute.
 * @param xmlStreamReader a {@link javolution.xml.stream.XMLStreamReader} object.
 * @param attr a {@link java.lang.String} object.
 */
public CharArray getRequiredAttribute(XMLStreamReader xmlStreamReader, String attr) {
 CharArray attrValue = xmlStreamReader.getAttributeValue(null, attr);
 if (attrValue == null)
  throw new IllegalStateException("Tag " + xmlStreamReader.getLocalName() + " must provide an `"
    + attr + "`attribute (Line " + xmlStreamReader.getLocation().getLineNumber() + ")");
 return attrValue;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com