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