• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

query about the parsing of xml file

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
Adwait Chitaley
Asked:
Adwait Chitaley
  • 3
  • 3
1 Solution
 
objectsCommented:
the xml needs to be in the same directory you are running it from

0
 
objectsCommented:
where is the xml file?

0
 
Adwait ChitaleyAuthor Commented:
xml is also in the project folder
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
objectsCommented:
how are you running the code?

0
 
Adwait ChitaleyAuthor Commented:
through netbean IDE
0
 
Adwait ChitaleyAuthor Commented:
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!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now