本文整理汇总了Java中javax.xml.stream.XMLStreamReader.isWhiteSpace方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.isWhiteSpace方法的具体用法?Java XMLStreamReader.isWhiteSpace怎么用?Java XMLStreamReader.isWhiteSpace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.isWhiteSpace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextTagSkipDTD
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* A copy of the nextTag algorithm from the XMLStreamReader javadocs,
* but which also skips over DTD events as well as whitespace,
* comments and PIs.
*
* @param xsr the reader to advance
* @return {@link XMLStreamConstants#START_ELEMENT} or
* {@link XMLStreamConstants#END_ELEMENT} for the next tag.
* @throws XMLStreamException
*/
private static int nextTagSkipDTD(XMLStreamReader xsr)
throws XMLStreamException {
int eventType = xsr.next();
while((eventType == XMLStreamConstants.CHARACTERS && xsr.isWhiteSpace())
|| (eventType == XMLStreamConstants.CDATA && xsr.isWhiteSpace())
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT
|| eventType == XMLStreamConstants.DTD) {
eventType = xsr.next();
}
if(eventType != XMLStreamConstants.START_ELEMENT
&& eventType != XMLStreamConstants.END_ELEMENT) {
throw new XMLStreamException("expected start or end tag", xsr
.getLocation());
}
return eventType;
}
示例2: currentWhiteSpaceContent
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* Read spaces from the reader as long as to the next element, starting from
* current position. Comments are ignored.
* @param reader
* @return
*/
public static String currentWhiteSpaceContent(XMLStreamReader reader) {
// since the there might be several valid chunks (spaces/comment/spaces)
// StringBuilder must be used; it's initialized lazily, only when needed
StringBuilder whiteSpaces = null;
for (;;) {
switch (reader.getEventType()) {
case START_ELEMENT:
case END_ELEMENT:
case END_DOCUMENT:
return whiteSpaces == null ? null : whiteSpaces.toString();
case CHARACTERS:
if (reader.isWhiteSpace()) {
if (whiteSpaces == null) {
whiteSpaces = new StringBuilder();
}
whiteSpaces.append(reader.getText());
} else {
throw new XMLStreamReaderException(
"xmlreader.unexpectedCharacterContent", reader.getText());
}
}
next(reader);
}
}
示例3: nextContent
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static int nextContent(XMLStreamReader reader) {
for (;;) {
int state = next(reader);
switch (state) {
case START_ELEMENT:
case END_ELEMENT:
case END_DOCUMENT:
return state;
case CHARACTERS:
if (!reader.isWhiteSpace()) {
return CHARACTERS;
}
}
}
}