本文整理汇总了Java中javax.xml.stream.events.XMLEvent.asEndElement方法的典型用法代码示例。如果您正苦于以下问题:Java XMLEvent.asEndElement方法的具体用法?Java XMLEvent.asEndElement怎么用?Java XMLEvent.asEndElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.events.XMLEvent
的用法示例。
在下文中一共展示了XMLEvent.asEndElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: set
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
public void set ( final String expression, final int targetElement, final String value ) throws IOException, XMLStreamException
{
int pos = 0;
final Stack<String> ele = new Stack<> ();
final Pattern pattern = Pattern.compile ( expression );
final XMLEventReader reader;
Modification mod = null;
final XMLInputFactory xmlinf = XMLInputFactory.newInstance ();
try (final FileInputStream is = new FileInputStream ( this.inputFile ))
{
reader = xmlinf.createXMLEventReader ( is );
try
{
while ( reader.hasNext () )
{
final XMLEvent event = (XMLEvent)reader.next ();
if ( event instanceof StartElement )
{
final StartElement startEvent = event.asStartElement ();
ele.push ( startEvent.getName ().getLocalPart () );
}
else if ( event instanceof EndElement )
{
final EndElement endEvent = event.asEndElement ();
final String en = ele.pop ();
if ( !endEvent.getName ().getLocalPart ().equals ( en ) )
{
throw new IllegalStateException ( "Element error: " + en + " / " + endEvent.getName () );
}
}
boolean inMatch = mod != null;
final boolean match = isMatch ( ele, pattern );
if ( inMatch && !match )
{
// end
if ( pos == targetElement )
{
this.mods.add ( mod );
}
pos++;
mod = null;
}
else if ( !inMatch && match )
{
// starting
mod = new Modification ();
mod.start = event.getLocation ().getCharacterOffset ();
mod.data = value;
}
else if ( inMatch && match )
{
mod.end = event.getLocation ().getCharacterOffset () - 2;
}
inMatch = match;
}
}
finally
{
reader.close ();
}
}
}
示例2: readTestResults
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
private static Collection<TestResult> readTestResults(XMLEventReader eventReader) throws XMLStreamException {
final Set<TestResult> testResults = new HashSet<>();
TestResult currentTestResult = null;
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if (event.isStartElement()) {
final StartElement startElement = event.asStartElement();
if ("testcase".equalsIgnoreCase(startElement.getName().getLocalPart())) {
// Read attributes
String name = null, classname = null;
Status status = null;
final Iterator<Attribute> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
final Attribute attribute = attributes.next();
if ("classname".equalsIgnoreCase(attribute.getName().toString())) {
classname = attribute.getValue();
}
if ("name".equalsIgnoreCase(attribute.getName().toString())) {
name = attribute.getValue();
}
}
currentTestResult = new TestResult(classname, name, Status.PASSED);
}
if ("failure".equalsIgnoreCase(startElement.getName().getLocalPart())) {
currentTestResult.setStatus(Status.FAILURE);
}
if ("error".equalsIgnoreCase(startElement.getName().getLocalPart())) {
currentTestResult.setStatus(Status.ERROR);
}
if ("skipped".equalsIgnoreCase(startElement.getName().getLocalPart())) {
currentTestResult.setStatus(Status.SKIPPED);
}
if ("rerunFailure".equalsIgnoreCase(startElement.getName().getLocalPart())) {
currentTestResult.setStatus(Status.RE_RUN_FAILURE);
}
}
if (event.isEndElement()) {
final EndElement endElementElement = event.asEndElement();
if ("testcase".equalsIgnoreCase(endElementElement.getName().getLocalPart())) {
testResults.add(currentTestResult);
}
}
}
return testResults;
}
示例3: parseFactories
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
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);
}
示例4: parse
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
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);
}
}