当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamReader.COMMENT属性代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamReader.COMMENT属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.COMMENT属性的具体用法?Java XMLStreamReader.COMMENT怎么用?Java XMLStreamReader.COMMENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.xml.stream.XMLStreamReader的用法示例。


在下文中一共展示了XMLStreamReader.COMMENT属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: storeDocumentAndChildren

private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
    storeStructure(T_DOCUMENT);

    _eventType = reader.next();
    while (_eventType != XMLStreamReader.END_DOCUMENT) {
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                storeElementAndChildren(reader);
                continue;
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
        _eventType = reader.next();
    }

    storeStructure(T_END);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:StreamReaderBufferCreator.java

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

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

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

示例5: 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.COMMENT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。