query about the parsing of xml file

Posted on 2009-05-18
Last Modified: 2012-05-07
i m getting the always null value in document doc of follwing code

please give me any solution
its urgent

when i print this line  its give output     doc null
  System.out.println("After Parse method_______________->++++++ "+doc);

 * To change this template, choose Tools | Templates

 * and open the template in the editor.


package net.ensode.jasperbook.struts;


    import javax.xml.parsers.*;

    import org.w3c.dom.*;

    import org.xml.sax.*;

    public class BasicDom {

        public static void main(String[] args) {

            Document doc = parseXmlFile("userxml.xml", false);

         System.out.println("After Parse method_______________->++++++ "+doc);


        // Parses an XML file and returns a DOM document.

        // If validating is true, the contents is validated against the DTD

        // specified in the file.

        public static Document parseXmlFile(String filename, boolean validating) {

            try {

                // Create a builder factory

                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();


                System.out.println("In Parse Methood++++++++++++++++++++++++++++++++++");

                // Create the builder and parse the file

                Document doc = factory.newDocumentBuilder().parse(new File(filename));

                return doc;

            } catch (SAXException e) {


                // A parsing error occurred; the xml input is not valid

            } catch (ParserConfigurationException e) {


            } catch (IOException e) {



            return null;



Open in new window

Question by:achitaley
  • 3
  • 3
LVL 92

Accepted Solution

objects earned 500 total points
ID: 24418872
the xml needs to be in the same directory you are running it from

LVL 92

Expert Comment

ID: 24418878
where is the xml file?


Author Comment

ID: 24418892
xml is also in the project folder
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

LVL 92

Expert Comment

ID: 24418895
how are you running the code?


Author Comment

ID: 24570755
through netbean IDE

Author Comment

ID: 24589528
i tried but found This is not a proper solution

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now