本文整理匯總了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;
}
}
}
}