本文整理汇总了Java中javax.xml.stream.XMLStreamConstants.SPACE属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamConstants.SPACE属性的具体用法?Java XMLStreamConstants.SPACE怎么用?Java XMLStreamConstants.SPACE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.xml.stream.XMLStreamConstants
的用法示例。
在下文中一共展示了XMLStreamConstants.SPACE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextTagSkipDTD
/**
* 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: nextTag
/** Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION)
* until a START_ELEMENT or
* END_ELEMENT is reached. If other than space characters are
* encountered, an exception is thrown. This method should
* be used when processing element-only content because
* the parser is not able to recognize ignorable whitespace if
* then DTD is missing or not interpreted.
* @return the event type of the element read
* @throws XMLStreamException if the current event is not white space
*/
public int nextTag() throws XMLStreamException {
int eventType = next();
while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
|| (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
// skip whitespace
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT
) {
eventType = next();
}
if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
throw new XMLStreamException(
"found: " + getEventTypeString(eventType)
+ ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT)
+ " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT),
getLocation());
}
return eventType;
}
示例3: getEventTypeName
private static String getEventTypeName(int eventType) {
switch (eventType) {
case XMLStreamConstants.START_ELEMENT:
return "START_ELEMENT";
case XMLStreamConstants.END_ELEMENT:
return "END_ELEMENT";
case XMLStreamConstants.SPACE:
return "SPACE";
case XMLStreamConstants.CHARACTERS:
return "CHARACTERS";
case XMLStreamConstants.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLStreamConstants.CDATA:
return "CDATA";
case XMLStreamConstants.COMMENT:
return "COMMENT";
case XMLStreamConstants.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLStreamConstants.START_DOCUMENT:
return "START_DOCUMENT";
case XMLStreamConstants.END_DOCUMENT:
return "END_DOCUMENT";
}
return null;
}
示例4: nextTag
/**
* Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION) until
* a START_ELEMENT or END_ELEMENT is reached. If other than space characters
* are encountered, an exception is thrown. This method should be used when
* processing element-only content because the parser is not able to
* recognize ignorable whitespace if then DTD is missing or not interpreted.
*
* @return the event type of the element read
* @throws XMLStreamException if the current event is not white space
*/
public int nextTag() throws XMLStreamException {
int eventType = next();
while ((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
|| (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
// skip whitespace
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT) {
eventType = next();
}
if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
throw new XMLStreamException(
"found: " + getEventTypeString(eventType)
+ ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT)
+ " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT),
getLocation());
}
return eventType;
}
示例5: handleFragmentedCharacters
private void handleFragmentedCharacters() throws XMLStreamException, SAXException {
buffer.setLength(0);
// Append characters of first character event
buffer.append(fastInfosetStreamReader.getTextCharacters(),
fastInfosetStreamReader.getTextStart(),
fastInfosetStreamReader.getTextLength());
// Consume all character
while(true) {
switch(fastInfosetStreamReader.peekNext()) {
case XMLStreamConstants.START_ELEMENT :
processBufferedText(true);
return;
case XMLStreamConstants.END_ELEMENT :
processBufferedText(false);
return;
case XMLStreamConstants.CHARACTERS :
case XMLStreamConstants.CDATA :
case XMLStreamConstants.SPACE :
// Append characters of second and subsequent character events
fastInfosetStreamReader.next();
buffer.append(fastInfosetStreamReader.getTextCharacters(),
fastInfosetStreamReader.getTextStart(),
fastInfosetStreamReader.getTextLength());
break;
default:
fastInfosetStreamReader.next();
}
}
}
示例6: getElementText
/** Reads the content of a text-only element. Precondition:
* the current event is START_ELEMENT. Postcondition:
* The current event is the corresponding END_ELEMENT.
* @throws XMLStreamException if the current event is not a START_ELEMENT or if
* a non text element is encountered
*/
public String getElementText() throws XMLStreamException {
if(getEventType() != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException(
"parser must be on START_ELEMENT to read next text", getLocation());
}
int eventType = next();
StringBuffer content = new StringBuffer();
while(eventType != XMLStreamConstants.END_ELEMENT ) {
if(eventType == XMLStreamConstants.CHARACTERS
|| eventType == XMLStreamConstants.CDATA
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.ENTITY_REFERENCE) {
content.append(getText());
} else if(eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT) {
// skipping
} else if(eventType == XMLStreamConstants.END_DOCUMENT) {
throw new XMLStreamException("unexpected end of document when reading element text content");
} else if(eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException(
"elementGetText() function expects text only elment but START_ELEMENT was encountered.", getLocation());
} else {
throw new XMLStreamException(
"Unexpected event type "+ eventType, getLocation());
}
eventType = next();
}
return content.toString();
}
示例7: getElementText
/**
* Reads the content of a text-only element. Precondition: the current event
* is START_ELEMENT. Postcondition: The current event is the corresponding
* END_ELEMENT.
*
* @throws XMLStreamException if the current event is not a START_ELEMENT or
* if a non text element is encountered
*/
public String getElementText() throws XMLStreamException {
if (getEventType() != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException(
"parser must be on START_ELEMENT to read next text", getLocation());
}
int eventType = next();
StringBuilder content = new StringBuilder();
while (eventType != XMLStreamConstants.END_ELEMENT) {
if (eventType == XMLStreamConstants.CHARACTERS
|| eventType == XMLStreamConstants.CDATA
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.ENTITY_REFERENCE) {
content.append(getText());
} else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT) {
// skipping
} else if (eventType == XMLStreamConstants.END_DOCUMENT) {
throw new XMLStreamException(
"unexpected end of document when reading element text content");
} else if (eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException("elementGetText() function expects text "
+ "only elment but START_ELEMENT was encountered.", getLocation());
} else {
throw new XMLStreamException(
"Unexpected event type " + eventType, getLocation());
}
eventType = next();
}
return content.toString();
}
示例8: getElementText
@Override
public final String getElementText() throws XMLStreamException {
XMLEvent event = this.previousEvent;
if (event == null) {
throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null");
}
if (!event.isStartElement()) {
throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation());
}
final StringBuilder text = new StringBuilder();
while (!event.isEndDocument()) {
switch (event.getEventType()) {
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.SPACE:
case XMLStreamConstants.CDATA: {
final Characters characters = event.asCharacters();
text.append(characters.getData());
break;
}
case XMLStreamConstants.ENTITY_REFERENCE: {
final EntityReference entityReference = (EntityReference)event;
final EntityDeclaration declaration = entityReference.getDeclaration();
text.append(declaration.getReplacementText());
break;
}
case XMLStreamConstants.COMMENT:
case XMLStreamConstants.PROCESSING_INSTRUCTION: {
//Ignore
break;
}
default: {
throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
}
}
event = this.nextEvent();
}
return text.toString();
}
示例9: bridge
public void bridge() throws XMLStreamException {
try {
// remembers the nest level of elements to know when we are done.
int depth=0;
// if the parser is at the start tag, proceed to the first element
int event = fastInfosetStreamReader.getEventType();
if(event == XMLStreamConstants.START_DOCUMENT) {
// nextTag doesn't correctly handle DTDs
while( !fastInfosetStreamReader.isStartElement() )
event = fastInfosetStreamReader.next();
}
if( event!=XMLStreamConstants.START_ELEMENT)
throw new IllegalStateException("The current event is not START_ELEMENT\n but " + event);
// TODO: we don't have to rely on this hack --- we can just emulate
// start/end prefix mappings. But for now, I'll rely on this hack.
handleStartDocument(fastInfosetStreamReader.getNamespaceContext());
OUTER:
while(true) {
// These are all of the events listed in the javadoc for
// XMLEvent.
// The spec only really describes 11 of them.
switch (event) {
case XMLStreamConstants.START_ELEMENT :
handleStartElement();
depth++;
break;
case XMLStreamConstants.END_ELEMENT :
depth--;
handleEndElement();
if(depth==0) break OUTER;
break;
case XMLStreamConstants.CHARACTERS :
case XMLStreamConstants.CDATA :
case XMLStreamConstants.SPACE :
if (predictor.expectText()) {
// Peek at the next event to see if there are
// fragmented characters
event = fastInfosetStreamReader.peekNext();
if (event == XMLStreamConstants.END_ELEMENT)
processNonIgnorableText();
else if (event == XMLStreamConstants.START_ELEMENT)
processIgnorableText();
else
handleFragmentedCharacters();
}
break;
// otherwise simply ignore
}
event=fastInfosetStreamReader.next();
}
fastInfosetStreamReader.next(); // move beyond the end tag.
handleEndDocument();
} catch (SAXException e) {
throw new XMLStreamException(e);
}
}
示例10: bridge
public void bridge() throws XMLStreamException {
try {
// remembers the nest level of elements to know when we are done.
int depth=0;
event = staxEventReader.peek();
if( !event.isStartDocument() && !event.isStartElement() )
throw new IllegalStateException();
// if the parser is on START_DOCUMENT, skip ahead to the first element
do {
event = staxEventReader.nextEvent();
} while( !event.isStartElement() );
handleStartDocument(event.asStartElement().getNamespaceContext());
OUTER:
while(true) {
// These are all of the events listed in the javadoc for
// XMLEvent.
// The spec only really describes 11 of them.
switch (event.getEventType()) {
case XMLStreamConstants.START_ELEMENT :
handleStartElement(event.asStartElement());
depth++;
break;
case XMLStreamConstants.END_ELEMENT :
depth--;
handleEndElement(event.asEndElement());
if(depth==0) break OUTER;
break;
case XMLStreamConstants.CHARACTERS :
case XMLStreamConstants.CDATA :
case XMLStreamConstants.SPACE :
handleCharacters(event.asCharacters());
break;
}
event=staxEventReader.nextEvent();
}
handleEndDocument();
event = null; // avoid keeping a stale reference
} catch (SAXException e) {
throw new XMLStreamException(e);
}
}
示例11: bridge
public void bridge() throws XMLStreamException {
try {
// remembers the nest level of elements to know when we are done.
int depth=0;
// if the parser is at the start tag, proceed to the first element
int event = staxStreamReader.getEventType();
if(event == XMLStreamConstants.START_DOCUMENT) {
// nextTag doesn't correctly handle DTDs
while( !staxStreamReader.isStartElement() )
event = staxStreamReader.next();
}
if( event!=XMLStreamConstants.START_ELEMENT)
throw new IllegalStateException("The current event is not START_ELEMENT\n but " + event);
handleStartDocument(staxStreamReader.getNamespaceContext());
OUTER:
while(true) {
// These are all of the events listed in the javadoc for
// XMLEvent.
// The spec only really describes 11 of them.
switch (event) {
case XMLStreamConstants.START_ELEMENT :
handleStartElement();
depth++;
break;
case XMLStreamConstants.END_ELEMENT :
depth--;
handleEndElement();
if(depth==0) break OUTER;
break;
case XMLStreamConstants.CHARACTERS :
case XMLStreamConstants.CDATA :
case XMLStreamConstants.SPACE :
handleCharacters();
break;
// otherwise simply ignore
}
event=staxStreamReader.next();
}
staxStreamReader.next(); // move beyond the end tag.
handleEndDocument();
} catch (SAXException e) {
throw new XMLStreamException(e);
}
}
示例12: parse
public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
XMLEvent currentEvent = input.peek();
if (currentEvent != null) {
int eventType = currentEvent.getEventType();
if (eventType != XMLStreamConstants.START_DOCUMENT &&
eventType != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException();
}
fLocationWrapper.setLocation(currentEvent.getLocation());
fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
loop: while (input.hasNext()) {
currentEvent = input.nextEvent();
eventType = currentEvent.getEventType();
switch (eventType) {
case XMLStreamConstants.START_ELEMENT:
++fDepth;
StartElement start = currentEvent.asStartElement();
fillQName(fElementQName, start.getName());
fLocationWrapper.setLocation(start.getLocation());
fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
fillXMLAttributes(start);
fillDeclaredPrefixes(start);
addNamespaceDeclarations();
fNamespaceContext.pushContext();
fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
break;
case XMLStreamConstants.END_ELEMENT:
EndElement end = currentEvent.asEndElement();
fillQName(fElementQName, end.getName());
fillDeclaredPrefixes(end);
fLocationWrapper.setLocation(end.getLocation());
fSchemaDOMParser.endElement(fElementQName, null);
fNamespaceContext.popContext();
--fDepth;
if (fDepth <= 0) {
break loop;
}
break;
case XMLStreamConstants.CHARACTERS:
sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
break;
case XMLStreamConstants.SPACE:
sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
break;
case XMLStreamConstants.CDATA:
fSchemaDOMParser.startCDATA(null);
sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
fSchemaDOMParser.endCDATA(null);
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
fillProcessingInstruction(pi.getData());
fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
break;
case XMLStreamConstants.DTD:
/* There shouldn't be a DTD in the schema */
break;
case XMLStreamConstants.ENTITY_REFERENCE:
/* Not needed for schemas */
break;
case XMLStreamConstants.COMMENT:
/* No point in sending comments */
break;
case XMLStreamConstants.START_DOCUMENT:
fDepth++;
/* We automatically call startDocument before the loop */
break;
case XMLStreamConstants.END_DOCUMENT:
/* We automatically call endDocument after the loop */
break;
}
}
fLocationWrapper.setLocation(null);
fNamespaceContext.setNamespaceContext(null);
fSchemaDOMParser.endDocument(null);
}
}
示例13: printEvent
public static void printEvent(XMLStreamReader xmlr, boolean showEvents) {
if (showEvents) {
System.out.print("EVENT:[" + xmlr.getLocation().getLineNumber() + "]["
+ xmlr.getLocation().getColumnNumber() + "] [" + getEventTypeName(xmlr.getEventType())
+ "]");
System.out.print(" [");
}
switch (xmlr.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
System.out.print("<");
printName(xmlr);
printNamespaces(xmlr);
printAttributes(xmlr);
System.out.print(">");
break;
case XMLStreamConstants.END_ELEMENT:
System.out.print("</");
printName(xmlr);
System.out.print(">");
break;
case XMLStreamConstants.SPACE:
case XMLStreamConstants.CHARACTERS:
int start = xmlr.getTextStart();
int length = xmlr.getTextLength();
System.out.print(new String(xmlr.getTextCharacters(), start, length));
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
System.out.print("<?");
if (xmlr.hasText())
System.out.print(xmlr.getText());
System.out.print("?>");
break;
case XMLStreamConstants.CDATA:
System.out.print("<![CDATA[");
start = xmlr.getTextStart();
length = xmlr.getTextLength();
System.out.print(new String(xmlr.getTextCharacters(), start, length));
System.out.print("]]>");
break;
case XMLStreamConstants.COMMENT:
System.out.print("<!--");
if (xmlr.hasText())
System.out.print(xmlr.getText());
System.out.print("-->");
break;
case XMLStreamConstants.ENTITY_REFERENCE:
System.out.print(xmlr.getLocalName() + "=");
if (xmlr.hasText())
System.out.print("[" + xmlr.getText() + "]");
break;
case XMLStreamConstants.START_DOCUMENT:
System.out.print("<?xml");
System.out.print(" version='" + xmlr.getVersion() + "'");
System.out.print(" encoding='" + xmlr.getCharacterEncodingScheme() + "'");
if (xmlr.isStandalone())
System.out.print(" standalone='yes'");
else
System.out.print(" standalone='no'");
System.out.print("?>");
break;
}
System.out.println("]");
}