本文整理汇总了Java中javax.xml.stream.XMLEventReader.nextTag方法的典型用法代码示例。如果您正苦于以下问题:Java XMLEventReader.nextTag方法的具体用法?Java XMLEventReader.nextTag怎么用?Java XMLEventReader.nextTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLEventReader
的用法示例。
在下文中一共展示了XMLEventReader.nextTag方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNextTag
import javax.xml.stream.XMLEventReader; //导入方法依赖的package包/类
/**
* The reason the following call sequence is a problem is that with a
* peekevent, getElementText calls nextEvent which does properly update the
* lastEvent
*/
@Test
public void testNextTag() {
try {
XMLEventReader er = getReader();
er.nextTag();
er.nextTag();
System.out.println(er.getElementText());
er.nextTag();
System.out.println(er.getElementText());
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
示例2: testNextTagWPeek
import javax.xml.stream.XMLEventReader; //导入方法依赖的package包/类
@Test
public void testNextTagWPeek() {
try {
XMLEventReader er = getReader();
er.nextTag();
er.nextTag();
er.peek();
System.out.println(er.getElementText());
er.nextTag();
System.out.println(er.getElementText());
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
示例3: test
import javax.xml.stream.XMLEventReader; //导入方法依赖的package包/类
@Test
public void test() {
String xmlData = "<?xml version=\"1.0\"?><Test>Hello</Test>";
try {
XMLEventReader xmlReader = XMLInputFactory.newInstance().createXMLEventReader(new ByteArrayInputStream(xmlData.getBytes()));
XMLEvent event = xmlReader.nextEvent();
System.out.println(event.getClass());
// xmlReader.peek(); // error in both cases with/without peek()
event = xmlReader.nextTag(); // nextEvent() would work fine
// nextTag() forgets to set fLastEvent
System.out.println(event.getClass());
String text = xmlReader.getElementText();
System.out.println(text);
} catch (XMLStreamException e) {
Assert.fail(e.getMessage());
}
}
示例4: handleObject
import javax.xml.stream.XMLEventReader; //导入方法依赖的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();
}
示例5: testNextTag
import javax.xml.stream.XMLEventReader; //导入方法依赖的package包/类
private static void testNextTag(int max)
throws IOException, XMLStreamException {
System.out.println("\nTest nextTag (" + max + ")...");
XMLEventReader reader = createXmlReader(max);
XMLEvent event;
do {
event = reader.nextTag();
System.out.println(event);
if (event.getEventType() == XMLEvent.END_ELEMENT
&& event.asEndElement().getName().getLocalPart().equals(ROOT)) {
break;
}
} while (true);
System.out.println("nextTag passed\n");
}