JAVA : StAX basics : XMLEventReader

Source Code

package test;

import java.io.InputStream;
import java.io.FileInputStream;
import java.io.File;

import javax.xml.stream.*;
import javax.xml.stream.XMLInputFactory;

public class XmlReader {
	public static void main(String[] args) throws Exception {
		XMLInputFactory inputFactory = XMLInputFactory.newInstance();
		InputStream input = new FileInputStream(new File("hb.xml"));
		XMLEventReader reader = inputFactory.createXMLEventReader(input);
		while (reader.hasNext()) {
			System.out.println(reader.next().toString());
		}
	}
}

Output

<?xml version="1.0" encoding='UTF-8' standalone='no'?>
<agiml>

	
<header>

		
<interface>
HEART_BEAT
</interface>

	
</header>


</agiml>
ENDDOCUMENT

XML File : hb.xml

<?xml version="1.0" ?>
<agiml>
	<header>
		<interface>HEART_BEAT</interface>
	</header>
</agiml>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: