本文整理汇总了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));
}