Quantcast
Viewing latest article 3
Browse Latest Browse All 4

Answer by bdoughan for splitting up of xml file using java

I would use the javax.xml.xpath APIs that are included in Java SE 5 for this.

import java.io.FileReader;import javax.xml.xpath.XPath;import javax.xml.xpath.XPathConstants;import javax.xml.xpath.XPathFactory;import org.w3c.dom.NodeList;import org.xml.sax.InputSource;public class Demo {    public static void main(String[] args) throws Exception {        XPath xPath = XPathFactory.newInstance().newXPath();        FileReader reader = new FileReader("input.xml");        InputSource xml = new InputSource(reader);        NodeList titleNodes = (NodeList) xPath.evaluate("//item/title", xml, XPathConstants.NODESET);        for(int x=0; x<titleNodes.getLength(); x++) {            System.out.println(titleNodes.item(x).getTextContent());        }    }}

Viewing latest article 3
Browse Latest Browse All 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>