?
Solved

query about the parsing of xml file

Posted on 2009-05-18
6
Medium Priority
?
197 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Industry Leaders: 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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

801 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