當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLEventReader.nextTag方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:Bug6668115Test.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Bug6668115Test.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:Bug6586466Test.java

示例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();
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:36,代碼來源:XmlJavaxFormat.java

示例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");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:EventFilterSupportTest.java


注:本文中的javax.xml.stream.XMLEventReader.nextTag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。