本文整理匯總了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");
}