本文整理匯總了Java中javax.xml.stream.events.XMLEvent.isEndElement方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEvent.isEndElement方法的具體用法?Java XMLEvent.isEndElement怎麽用?Java XMLEvent.isEndElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.stream.events.XMLEvent
的用法示例。
在下文中一共展示了XMLEvent.isEndElement方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: nextTag
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public final XMLEvent nextTag() throws XMLStreamException {
XMLEvent event = this.nextEvent();
while ((event.isCharacters() && event.asCharacters().isWhiteSpace())
|| event.isProcessingInstruction()
|| event.getEventType() == XMLStreamConstants.COMMENT) {
event = this.nextEvent();
}
if (!event.isStartElement() && event.isEndElement()) {
throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
}
return event;
}
示例2: Query
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
/**
* Створює новий об'єкт. При створенні даного об'єкту відбувається аналіз
* XML документа до закриваючого тега query (включно).
*
* @throws XMLStreamException
*/
public Query(XMLEventReader eventReader, XMLEvent firstQueryElementEvent)
throws XMLStreamException {
XMLEvent element = firstQueryElementEvent;
while (eventReader.hasNext()) {
elements.add(new Element(eventReader, element));
element = eventReader.nextEvent();
if ((element.isEndElement())
&& (element.asEndElement().getName()
.equals(ReportGenerator.QUERY)))
break;
if (!element.isStartElement()) {
throw new XMLStreamException(
"Error in XML waighted for '<element>' or '</quary>'");
}
}
}
示例3: getElementText
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public String getElementText() throws XMLStreamException
{
StringBuffer buffer = new StringBuffer();
XMLEvent e = nextEvent();
if (!e.isStartElement())
throw new XMLStreamException(
CommonResourceBundle.getInstance().getString("message.mustBeOnSTART_ELEMENT"));
while(hasNext()) {
e = nextEvent();
if(e.isStartElement())
throw new XMLStreamException(
CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"));
if(e.isCharacters())
buffer.append(((Characters) e).getData());
if(e.isEndElement())
return buffer.toString();
}
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.END_ELEMENTnotFound"));
}
示例4: readXMLByStAX
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public static void readXMLByStAX() throws XMLStreamException, FileNotFoundException {
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(new FileInputStream("test.xml"));//StaxDemo.class.getResourceAsStream("test.xml")
XMLEvent event;
StringBuffer parsingResult = new StringBuffer();
while (reader.hasNext()) {
event = reader.nextEvent();
if (event.isStartElement()) {
StartElement se = event.asStartElement();
parsingResult.append("<");
parsingResult.append(se.getName());
if (se.getName().getLocalPart().equals("catalog")) {
parsingResult.append("id=");
parsingResult.append(se.getAttributeByName(new QName("id")).getValue());
parsingResult.append("");
}
parsingResult.append(">");
} else if (event.isCharacters()) {
parsingResult.append(event.asCharacters().getData());
} else if (event.isEndElement()) {
parsingResult.append("</");
parsingResult.append(event.asEndElement().getName());
parsingResult.append(">");
}
}
System.out.println(parsingResult);
}
示例5: handleMissingField
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private void handleMissingField(String fieldName, XMLEventReader parser,
XMLEvent event, ExtensionRegistry extensionRegistry,
UnknownFieldSet.Builder builder) throws XMLStreamException {
// skip over the unknown fields, since we can't map them by id, then this message must not know about them.
// We 'could' map them into the UnknownFieldSet, however none of the other formatters support this..
// but in the future it would probably be useful for the case: Message A (v2) -> Message B (v1) -> Xml -> Message A (v2)
// this would require extra meta data in the xml to know the type of the unknown-field.
if (event.isStartElement()) {
/**
* This loop will eat up everything inside "6"
* So when this method is called, fieldName = 6, and event is set at index="11"
* <unknown-field index="6">
* <unknown-field index="11">566667</unknown-field>
* <unknown-field index="15">
* <unknown-field index="16">566667</unknown-field>
* </unknown-field>
* </unknown-field>
*/
int depth = 1; // we start 1 level down, the value of "6"
while (parser.hasNext()) {
XMLEvent nextEvent = parser.nextEvent();
if (nextEvent.isEndElement()) {
depth--;
if (depth <= 0 && parser.peek().isEndElement()) {
break;
}
} else if (nextEvent.isStartElement()) {
depth++;
}
}
} else if (event.isCharacters()) {
// done, let it slide.
}
}
示例6: handleObject
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private Object handleObject(XMLEventReader parser,
XMLEvent startEvent,
ExtensionRegistry extensionRegistry,
Message.Builder builder,
FieldDescriptor field,
ExtensionRegistry.ExtensionInfo extension) throws XMLStreamException {
Message.Builder subBuilder = createSubBuilder(builder, field, extension);
XMLEvent event = startEvent;
int depth = 0; // initialize to 0
do {
if (event.isStartElement()) {
depth++; // we're inside the element
mergeField(parser, event,
extensionRegistry, subBuilder);
XMLEvent nextEvent = parser.nextTag();
if (nextEvent.isEndElement()) {
depth--;
// if we're back under the top level obj, and there is another close, we're done.
if (depth <= 0 && parser.peek().isEndElement()) {
break;
}
} else if (nextEvent.isStartElement()) {
depth++;
}
} else {
// something is potentially wrong..
break;
}
} while (parser.hasNext() && (event = parser.nextTag()) != null);
return subBuilder.build();
}
示例7: nextTag
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public XMLEvent nextTag() throws XMLStreamException {
while(hasNext()) {
XMLEvent e = nextEvent();
if (e.isStartElement() || e.isEndElement())
return e;
}
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.startOrEndNotFound"));
}
示例8: unmarshall
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
/**
* Id (aka configuration name) isn't modeled on the actual {@link NotificationConfiguration}
* class but as the key name in the map of configurations in
* {@link BucketNotificationConfiguration}
*/
@Override
public Entry<String, NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception {
int originalDepth = context.getCurrentDepth();
int targetDepth = originalDepth + 1;
if (context.isStartOfDocument()) {
targetDepth += 1;
}
T topicConfig = createConfiguration();
String id = null;
while (true) {
XMLEvent xmlEvent = context.nextEvent();
if (xmlEvent.isEndDocument()) {
return new SimpleEntry<String, NotificationConfiguration>(id, topicConfig);
}
if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
if (handleXmlEvent(topicConfig, context, targetDepth)) {
// Do nothing, subclass has handled it
} else if (context.testExpression("Id", targetDepth)) {
id = StringStaxUnmarshaller.getInstance().unmarshall(context);
} else if (context.testExpression("Event", targetDepth)) {
topicConfig.addEvent(StringStaxUnmarshaller.getInstance().unmarshall(context));
} else if (context.testExpression("Filter", targetDepth)) {
topicConfig.setFilter(FilterStaxUnmarshaller.getInstance().unmarshall(context));
}
} else if (xmlEvent.isEndElement()) {
if (context.getCurrentDepth() < originalDepth) {
return new SimpleEntry<String, NotificationConfiguration>(id, topicConfig);
}
}
}
}
示例9: unmarshall
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public S3KeyFilter unmarshall(StaxUnmarshallerContext context) throws Exception {
int originalDepth = context.getCurrentDepth();
int targetDepth = originalDepth + 1;
if (context.isStartOfDocument()) {
targetDepth += 1;
}
S3KeyFilter filter = new S3KeyFilter();
while (true) {
XMLEvent xmlEvent = context.nextEvent();
if (xmlEvent.isEndDocument()) {
return filter;
}
if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
if (context.testExpression("FilterRule", targetDepth)) {
filter.addFilterRule(FilterRuleStaxUnmarshaller.getInstance().unmarshall(context));
}
} else if (xmlEvent.isEndElement()) {
if (context.getCurrentDepth() < originalDepth) {
return filter;
}
}
}
}
示例10: unmarshall
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public Filter unmarshall(StaxUnmarshallerContext context) throws Exception {
int originalDepth = context.getCurrentDepth();
int targetDepth = originalDepth + 1;
if (context.isStartOfDocument()) {
targetDepth += 1;
}
Filter filter = new Filter();
while (true) {
XMLEvent xmlEvent = context.nextEvent();
if (xmlEvent.isEndDocument()) {
return filter;
}
if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
if (context.testExpression("S3Key", targetDepth)) {
filter.withS3KeyFilter(S3KeyFilterStaxUnmarshaller.getInstance().unmarshall(context));
}
} else if (xmlEvent.isEndElement()) {
if (context.getCurrentDepth() < originalDepth) {
return filter;
}
}
}
}
示例11: unmarshall
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public FilterRule unmarshall(StaxUnmarshallerContext context) throws Exception {
int originalDepth = context.getCurrentDepth();
int targetDepth = originalDepth + 1;
if (context.isStartOfDocument()) {
targetDepth += 1;
}
FilterRule filter = new FilterRule();
while (true) {
XMLEvent xmlEvent = context.nextEvent();
if (xmlEvent.isEndDocument()) {
return filter;
}
if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
if (context.testExpression("Name", targetDepth)) {
filter.setName(StringStaxUnmarshaller.getInstance().unmarshall(context));
} else if (context.testExpression("Value", targetDepth)) {
filter.setValue(StringStaxUnmarshaller.getInstance().unmarshall(context));
}
} else if (xmlEvent.isEndElement()) {
if (context.getCurrentDepth() < originalDepth) {
return filter;
}
}
}
}
示例12: unmarshall
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public Entry<String, NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception {
int originalDepth = context.getCurrentDepth();
int targetDepth = originalDepth + 1;
if (context.isStartOfDocument()) {
targetDepth += 1;
}
String id = null;
List<String> events = new ArrayList<String>();
Filter filter = null;
String functionArn = null;
String invocationRole = null;
while (true) {
XMLEvent xmlEvent = context.nextEvent();
if (xmlEvent.isEndDocument()) {
return createLambdaConfig(id, events, functionArn, invocationRole, filter);
}
if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
if (context.testExpression("Id", targetDepth)) {
id = StringStaxUnmarshaller.getInstance().unmarshall(context);
} else if (context.testExpression("Event", targetDepth)) {
events.add(StringStaxUnmarshaller.getInstance().unmarshall(context));
} else if (context.testExpression("Filter", targetDepth)) {
filter = FilterStaxUnmarshaller.getInstance().unmarshall(context);
} else if (context.testExpression("CloudFunction", targetDepth)) {
functionArn = StringStaxUnmarshaller.getInstance().unmarshall(context);
} else if (context.testExpression("InvocationRole", targetDepth)) {
invocationRole = StringStaxUnmarshaller.getInstance().unmarshall(context);
}
} else if (xmlEvent.isEndElement()) {
if (context.getCurrentDepth() < originalDepth) {
return createLambdaConfig(id, events, functionArn, invocationRole, filter);
}
}
}
}
示例13: 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;
}