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


Java XMLInputFactory.createFilteredReader方法代碼示例

本文整理匯總了Java中javax.xml.stream.XMLInputFactory.createFilteredReader方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLInputFactory.createFilteredReader方法的具體用法?Java XMLInputFactory.createFilteredReader怎麽用?Java XMLInputFactory.createFilteredReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.stream.XMLInputFactory的用法示例。


在下文中一共展示了XMLInputFactory.createFilteredReader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: eventReaderTest

import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
public void eventReaderTest(XMLInputFactory xif) {
    XMLEventReader eventReader = null;
    try {
        eventReader = xif.createXMLEventReader(this.getClass().getResourceAsStream(INPUT_FILE));
        XMLEventReader filteredEventReader = xif.createFilteredReader(eventReader, new EventFilter() {
            public boolean accept(XMLEvent event) {
                if (!event.isStartElement()) {
                    return false;
                }
                QName elementQName = event.asStartElement().getName();
                if ((elementQName.getLocalPart().equals(ATTACHMENT_NAME.getLocalPart()) || elementQName.getLocalPart().equals("Attachment"))
                        && elementQName.getNamespaceURI().equals(VF_GENERIC_TT_NAMESPACE)) {
                    return true;
                }
                return false;
            }
        });
        if (filteredEventReader.hasNext()) {
            System.out.println("containsAttachments() returns true");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());

    } finally {
        if (eventReader != null) {
            try {
                eventReader.close();
            } catch (XMLStreamException xse) {
                // Ignored by intention
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:Bug6976938Test.java

示例2: testOne

import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
@Test
public void testOne() {
    try {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader reader = factory.createFilteredReader(factory.createXMLStreamReader(new StringReader(XML)), new Filter());
        reader.next();
        reader.hasNext(); // force filter to cache
        Assert.assertTrue(reader.getAttributeLocalName(0) != null);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Unexpected Exception: " + e.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:AttributeLocalNameTest.java

示例3: createStreamReader

import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
private XMLStreamReader createStreamReader(HasNextTypeFilter f) {

        try {
            XMLInputFactory factory = XMLInputFactory.newInstance();
            factory = XMLInputFactory.newInstance();
            return factory.createFilteredReader(factory.createXMLStreamReader(this.getClass().getResourceAsStream(INPUT_FILE)), (StreamFilter) f);
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail("Unexpected Exception: " + e.getMessage());
            return null;
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:HasNextTest.java

示例4: createXmlReader

import javax.xml.stream.XMLInputFactory; //導入方法依賴的package包/類
private static XMLEventReader createXmlReader(int max)
        throws XMLStreamException {
    TestInputStream ts = new TestInputStream(max);
    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLEventReader reader = xif.createXMLEventReader(ts);
    return xif.createFilteredReader(reader, new TagFilter(max));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:EventFilterSupportTest.java


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