本文整理汇总了Java中javax.xml.stream.XMLStreamConstants.END_ELEMENT属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamConstants.END_ELEMENT属性的具体用法?Java XMLStreamConstants.END_ELEMENT怎么用?Java XMLStreamConstants.END_ELEMENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.xml.stream.XMLStreamConstants
的用法示例。
在下文中一共展示了XMLStreamConstants.END_ELEMENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readText
/**
* Returns the text contents of the current element being parsed.
*
* @return The text contents of the current element being parsed.
*/
public String readText() throws XMLStreamException {
if (isInsideResponseHeader()) {
return getHeader(currentHeader);
}
if (currentEvent.isAttribute()) {
Attribute attribute = (Attribute) currentEvent;
return attribute.getValue();
}
StringBuilder sb = new StringBuilder();
while (true) {
XMLEvent event = eventReader.peek();
if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
eventReader.nextEvent();
sb.append(event.asCharacters().getData());
} else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) {
return sb.toString();
} else {
throw new RuntimeException("Encountered unexpected event: " + event.toString());
}
}
}
示例2: nextTag
/**
* {@inheritDoc}
*/
@Override
public int nextTag() throws XMLStreamException {
int tag = super.nextTag();
if (tracing) {
switch (tag) {
case XMLStreamConstants.START_ELEMENT:
System.err.println("[" + getLocalName());
break;
case XMLStreamConstants.END_ELEMENT:
System.err.println(getLocalName() + "]");
break;
default:
System.err.println((tagStrings.containsKey(tag))
? tagStrings.get(tag)
: "Weird tag: " + tag);
break;
}
}
return tag;
}
示例3: 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;
}
示例4: readText
/**
* Returns the text contents of the current element being parsed.
*
* @return The text contents of the current element being parsed.
* @throws XMLStreamException
*/
public String readText() throws XMLStreamException {
if (isInsideResponseHeader()) {
return getHeader(currentHeader);
}
if (currentEvent.isAttribute()) {
Attribute attribute = (Attribute)currentEvent;
return attribute.getValue();
}
StringBuilder sb = new StringBuilder();
while (true) {
XMLEvent event = eventReader.peek();
if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
eventReader.nextEvent();
sb.append(event.asCharacters().getData());
} else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) {
return sb.toString();
} else {
throw new RuntimeException("Encountered unexpected event: " + event.toString());
}
}
}
示例5: 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;
}
示例6: 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;
}
示例7: accept
@Override
public void accept(XMLStreamReader xr) {
if(xr.getEventType() == XMLStreamConstants.START_ELEMENT
&& xr.getLocalName().equals("offset")) {
this.currId = xr.getAttributeValue(null, "idRef");
} else if(xr.getEventType() == XMLStreamConstants.CHARACTERS
&& this.currId != null){
this.currOffset = Long.valueOf(xr.getText());
} else if(xr.getEventType() == XMLStreamConstants.END_ELEMENT
&& xr.getLocalName().equals("offset")){
this.idToOffsets.put(this.currId, this.currOffset);
this.offsets.add(this.currOffset);
this.currId = null;
this.currOffset = -1;
}
}
示例8: handleStartElement
/**
* Parses the current element parser element. This method must only be called when the given stream reader points to a START_ELEMENT
*
* @param r the stream reader
* @return the deserialized element
* @throws XMLStreamException
*/
private Object handleStartElement( XMLStreamReader r ) throws XMLStreamException {
String currentObjectName = r.getLocalName().toLowerCase();
Map<String, String> attributes = new HashMap<>();
for( int i = 0; i < r.getAttributeCount(); i++ )
attributes.put( r.getAttributeLocalName( i ).toLowerCase(), r.getAttributeValue( i ) );
NessusObject nessusObject = nessusObjectByName.containsKey( currentObjectName ) ? nessusObjectByName.get( currentObjectName ) : defaultObject;
Object element = nessusObject.create( currentObjectName, attributes );
while( r.hasNext() ) {
switch( r.next() ) {
case XMLStreamConstants.START_ELEMENT:
Object child = handleStartElement( r );
nessusObject.gotChild( element, child );
break;
case XMLStreamConstants.CHARACTERS:
nessusObject.gotTextValue( element, r.getText() );
break;
case XMLStreamConstants.END_ELEMENT:
return element;
}
}
// should never happen the only return should be from END_ELEMENT
return null;
}
示例9: toNextTag
public static void toNextTag(XMLStreamReader reader, QName name) {
// skip any whitespace
if (reader.getEventType() != XMLStreamConstants.START_ELEMENT &&
reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
XMLStreamReaderUtil.nextElementContent(reader);
}
if(reader.getEventType() == XMLStreamConstants.END_ELEMENT && name.equals(reader.getName())) {
XMLStreamReaderUtil.nextElementContent(reader);
}
}
示例10: parse
private static void parse(BufferedReader reader, SimulationDetailedParameters parameters) {
try {
XMLStreamReader xmlsr = XML_INPUT_FACTORY_SUPPLIER.get().createXMLStreamReader(reader);
Contingency contingency = null;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.START_ELEMENT:
switch (xmlsr.getLocalName()) {
case "contingency":
contingency = new Contingency(xmlsr.getAttributeValue(null, "id"));
parameters.getContingencies().put(contingency.getId(), contingency);
break;
case "branch":
Objects.requireNonNull(contingency);
Branch branch = new Branch(xmlsr.getAttributeValue(null, "id"),
parseDoubleIfNotNull(xmlsr.getAttributeValue(null, "shortCircuitDuration")),
parseDoubleIfNotNull(xmlsr.getAttributeValue(null, "shortCircuitDistance")),
xmlsr.getAttributeValue(null, "shortCircuitSide"));
contingency.getBranches().put(branch.getId(), branch);
break;
case "generator":
Objects.requireNonNull(contingency);
Generator generator = new Generator(xmlsr.getAttributeValue(null, "id"),
parseDoubleIfNotNull(xmlsr.getAttributeValue(null, "shortCircuitDuration")));
contingency.getGenerators().put(generator.getId(), generator);
break;
default:
throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
}
break;
case XMLStreamConstants.END_ELEMENT:
switch (xmlsr.getLocalName()) {
case "contingency":
contingency = null;
break;
case "branch":
case "generator":
// nothing to do
break;
default:
throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
}
break;
default:
break;
}
}
} catch (XMLStreamException e) {
throw new UncheckedXmlStreamException(e);
}
}
示例11: readRelationSet
public static void readRelationSet(XMLStreamReader xsr,
RelationSet relations, Set<Integer> allAnnotIds)
throws XMLStreamException {
while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
xsr.require(XMLStreamConstants.START_ELEMENT, null, "Relation");
String type = xsr.getAttributeValue(null, "Type");
String idString = xsr.getAttributeValue(null, "Id");
String memberString = xsr.getAttributeValue(null, "Members");
if(memberString == null)
throw new XMLStreamException("A relation must have members");
if (type == null)
throw new XMLStreamException("A relation must have a type");
if (idString == null)
throw new XMLStreamException("A relation must have an id");
String[] memberStrings = memberString.split(";");
int[] members = new int[memberStrings.length];
for(int i = 0; i < members.length; ++i) {
members[i] = Integer.parseInt(memberStrings[i]);
}
xsr.nextTag();
xsr.require(XMLStreamConstants.START_ELEMENT, null, "UserData");
// get the string representation of the user data
StringBuilder stringRep = new StringBuilder(1024);
int eventType;
while((eventType = xsr.next()) != XMLStreamConstants.END_ELEMENT) {
switch(eventType) {
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.CDATA:
stringRep.append(xsr.getTextCharacters(), xsr.getTextStart(),
xsr.getTextLength());
break;
case XMLStreamConstants.START_ELEMENT:
throw new XMLStreamException("Elements not allowed within "
+ "user data.", xsr.getLocation());
default:
// do nothing - ignore comments, PIs, etc.
}
}
xsr.require(XMLStreamConstants.END_ELEMENT, null, "UserData");
FeatureMap features = readFeatureMap(xsr);
Relation r = new SimpleRelation(Integer.parseInt(idString), type, members);
r.setFeatures(features);
if(stringRep.length() > 0) {
ObjectWrapper wrapper = new ObjectWrapper(stringRep.toString());
r.setUserData(wrapper.getValue());
}
relations.add(r);
}
}
示例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: skipChain
private static void skipChain(XMLStreamReader reader) {
while (XMLStreamReaderUtil.nextContent(reader) !=
XMLStreamConstants.END_ELEMENT ||
!reader.getName().equals(QNAME_HANDLER_CHAIN)) {}
XMLStreamReaderUtil.nextElementContent(reader);
}
示例14: 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);
}
}
示例15: parseFactories
private TubelineFeature parseFactories(final boolean enabled, final StartElement element, final XMLEventReader reader)
throws WebServiceException {
int elementRead = 0;
loop:
while (reader.hasNext()) {
try {
final XMLEvent event = reader.nextEvent();
switch (event.getEventType()) {
case XMLStreamConstants.COMMENT:
break; // skipping the comments and start document events
case XMLStreamConstants.CHARACTERS:
if (event.asCharacters().isWhiteSpace()) {
break;
}
else {
// TODO: logging message
throw LOGGER.logSevereException(new WebServiceException("No character data allowed, was " + event.asCharacters()));
}
case XMLStreamConstants.START_ELEMENT:
// TODO implement
elementRead++;
break;
case XMLStreamConstants.END_ELEMENT:
elementRead--;
if (elementRead < 0) {
final EndElement endElement = event.asEndElement();
if (!element.getName().equals(endElement.getName())) {
// TODO logging message
throw LOGGER.logSevereException(new WebServiceException("End element does not match " + endElement));
}
break loop;
}
else {
break;
}
default:
// TODO logging message
throw LOGGER.logSevereException(new WebServiceException("Unexpected event, was " + event));
}
} catch (XMLStreamException e) {
// TODO logging message
throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
}
}
// TODO implement
return new TubelineFeature(enabled);
}