Showing posts with label get Root xml from a file. Show all posts
Showing posts with label get Root xml from a file. Show all posts

Sunday, 4 February 2018

Java program to get Root xml from a file,convert file to xml document and get the root element

import java.io.*;
import javax.xml.parsers.*;
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import java.io.File;

public class Util {

public static void main(String[] args) {

File inputFile = new File("input.txt");

System.out.println("get root element of xml");
root(xml) ;

}

public static void root(File inputFile)
throws SAXException, ParserConfigurationException, IOException {
// Parse the given input

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(inputFile);

System.out.println("Root element in xml is:"+doc.getDocumentElement());

}
}

If you have filr instead of xml string,

make your xml structure

save it to

Handaling XLS File In Java

This code will help you to handle xls file in java using apache poi. package test; import java.io.File; import java.io.FileInputStream...