本文整理匯總了Java中javax.xml.stream.XMLEventReader.next方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEventReader.next方法的具體用法?Java XMLEventReader.next怎麽用?Java XMLEventReader.next使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.stream.XMLEventReader
的用法示例。
在下文中一共展示了XMLEventReader.next方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
@Test
public void test() {
try {
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLEventReader reader = xif.createXMLEventReader(this.getClass().getResourceAsStream("xml11.xml.data"));
while (reader.hasNext())
reader.next();
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.toString());
}
}
示例2: checkOutput
import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
private void checkOutput(String output) throws Exception {
InputStream in = new FileInputStream(output);
XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(in);
while (reader.hasNext()) {
reader.next();
}
reader.close();
}
示例3: set
import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
public void set ( final String expression, final int targetElement, final String value ) throws IOException, XMLStreamException
{
int pos = 0;
final Stack<String> ele = new Stack<> ();
final Pattern pattern = Pattern.compile ( expression );
final XMLEventReader reader;
Modification mod = null;
final XMLInputFactory xmlinf = XMLInputFactory.newInstance ();
try (final FileInputStream is = new FileInputStream ( this.inputFile ))
{
reader = xmlinf.createXMLEventReader ( is );
try
{
while ( reader.hasNext () )
{
final XMLEvent event = (XMLEvent)reader.next ();
if ( event instanceof StartElement )
{
final StartElement startEvent = event.asStartElement ();
ele.push ( startEvent.getName ().getLocalPart () );
}
else if ( event instanceof EndElement )
{
final EndElement endEvent = event.asEndElement ();
final String en = ele.pop ();
if ( !endEvent.getName ().getLocalPart ().equals ( en ) )
{
throw new IllegalStateException ( "Element error: " + en + " / " + endEvent.getName () );
}
}
boolean inMatch = mod != null;
final boolean match = isMatch ( ele, pattern );
if ( inMatch && !match )
{
// end
if ( pos == targetElement )
{
this.mods.add ( mod );
}
pos++;
mod = null;
}
else if ( !inMatch && match )
{
// starting
mod = new Modification ();
mod.start = event.getLocation ().getCharacterOffset ();
mod.data = value;
}
else if ( inMatch && match )
{
mod.end = event.getLocation ().getCharacterOffset () - 2;
}
inMatch = match;
}
}
finally
{
reader.close ();
}
}
}