本文整理汇总了Java中javax.xml.stream.events.XMLEvent.isStartElement方法的典型用法代码示例。如果您正苦于以下问题:Java XMLEvent.isStartElement方法的具体用法?Java XMLEvent.isStartElement怎么用?Java XMLEvent.isStartElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.events.XMLEvent
的用法示例。
在下文中一共展示了XMLEvent.isStartElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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"));
}
示例3: 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);
}
示例4: add
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
@Override
public void add(XMLEvent event) throws XMLStreamException {
XMLEvent newEvent = null;
if (event.isStartElement()) {
StartElement startElement = event.asStartElement();
newEvent = anonymizeStartElement(startElement);
} else if (event.isCharacters()) {
Characters characters = event.asCharacters();
newEvent = anonymizeCharacters(characters);
}
super.add(newEvent != null ? newEvent : event);
}
示例5: unmarshal0
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
private Object unmarshal0(XMLEventReader reader,JaxBeanInfo expectedType) throws JAXBException {
if (reader == null) {
throw new IllegalArgumentException(
Messages.format(Messages.NULL_READER));
}
try {
XMLEvent event = reader.peek();
if (!event.isStartElement() && !event.isStartDocument()) {
// TODO: convert event into event name
throw new IllegalStateException(
Messages.format(
Messages.ILLEGAL_READER_STATE,event.getEventType()));
}
// Quick hack until SJSXP fixes 6270116
boolean isZephyr = reader.getClass().getName().equals("com.sun.xml.internal.stream.XMLReaderImpl");
XmlVisitor h = createUnmarshallerHandler(null,false,expectedType);
if(!isZephyr) {
h = new InterningXmlVisitor(h);
}
new StAXEventConnector(reader,h).bridge();
return h.getContext().getResult();
} catch (XMLStreamException e) {
throw handleStreamException(e);
}
}
示例6: 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.
}
}
示例7: 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();
}
示例8: nextEvent
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
@Override
public XMLEvent nextEvent() throws XMLStreamException {
XMLEvent event = super.nextEvent();
if ( event.isStartElement() ) {
return withNamespace( event.asStartElement() );
}
return event;
}
示例9: peek
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
@Override
public XMLEvent peek() throws XMLStreamException {
XMLEvent event = super.peek();
if ( event.isStartElement() ) {
return withNamespace( event.asStartElement() );
}
else {
return event;
}
}
示例10: read
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
private XmlDocument read(XMLEventReader staxEventReader, Origin origin) {
XMLEvent event;
try {
event = staxEventReader.peek();
while ( event != null && !event.isStartElement() ) {
staxEventReader.nextEvent();
event = staxEventReader.peek();
}
}
catch ( Exception e ) {
throw new InvalidMappingException( "Error accessing stax stream", origin, e );
}
if ( event == null ) {
throw new InvalidMappingException( "Could not locate root element", origin );
}
final String rootElementName = event.asStartElement().getName().getLocalPart();
if ( "entity-mappings".equals( rootElementName ) ) {
final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME );
final String explicitVersion = attribute == null ? null : attribute.getValue();
validateMapping(
SupportedOrmXsdVersion.parse( explicitVersion, origin ),
staxEventReader,
origin
);
}
return new XmlDocumentImpl( toDom4jDocument( staxEventReader, origin ), origin );
}
示例11: 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"));
}
示例12: testEventReader
import javax.xml.stream.events.XMLEvent; //导入方法依赖的package包/类
@Test
public void testEventReader() {
try {
XMLInputFactory ifac = XMLInputFactory.newInstance();
XMLEventReader read = ifac.createXMLEventReader(this.getClass().getResource(INPUT_FILE).toExternalForm(),
this.getClass().getResourceAsStream(INPUT_FILE));
while (read.hasNext()) {
XMLEvent event = read.nextEvent();
if (event.isStartElement()) {
StartElement startElement = event.asStartElement();
if (startElement.getName().getLocalPart().equals("bookurn")) {
Iterator iterator = startElement.getNamespaces();
int count = 0;
while (iterator.hasNext()) {
iterator.next();
count++;
}
Assert.assertTrue(count == 2, "Two namespaces are expected for <bookurn> ");
Iterator attributes = startElement.getAttributes();
count = 0;
while (attributes.hasNext()) {
iterator.next();
count++;
}
Assert.assertTrue(count == 0, "Zero attributes are expected for <bookurn> ");
}
}
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
}
示例13: 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;
}
}
}
}
示例14: 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;
}
}
}
}
示例15: 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;
}
}
}
}