Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

query about the parsing of xml file

Posted on 2009-05-18
6
Medium Priority
?
198 Views
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 java.io.*;
    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();
                factory.setValidating(validating);
                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) {
                e.printStackTrace();
                // A parsing error occurred; the xml input is not valid
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }

Open in new window

0
Comment
Question by:Adwait Chitaley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 92

Accepted Solution

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

0
 
LVL 92

Expert Comment

by:objects
ID: 24418878
where is the xml file?

0
 

Author Comment

by:Adwait Chitaley
ID: 24418892
xml is also in the project folder
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 24418895
how are you running the code?

0
 

Author Comment

by:Adwait Chitaley
ID: 24570755
through netbean IDE
0
 

Author Comment

by:Adwait Chitaley
ID: 24589528
i tried but found This is not a proper solution
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

609 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