|
|
| XML DOM error |
Expert:jagannath
import org.w3c.dom.*; import javax.xml.parsers.*; import java.io.*;
public class DOMCountElement{ public static void main(String[] args) { try { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter File name: "); String xmlFile = bf.readLine(); File file = new File(xmlFile); if (file.exists()){ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // Create the builder and parse the file Document doc = factory.newDocumentBuilder().parse(xmlFile); System.out.print("Enter element name: "); String element = bf.readLine(); NodeList nodes = doc.getElementsByTagName(element); System.out.println("xml Document Contains " + nodes.getLength() + " elements."); } else{ System.out.print("File not found!"); } } catch (Exception ex) { System.out.println(ex); } } }
the above program "To Count XML Element" was copied from this website (roseindia.net) but im getting a error like this... "java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/html4/strict.dtd" im using eclipse IDE.. please help me with this. Thank u |
| Answers |
Hi Friend,
Here this code works fine.It seems that your code could not find the file that you have specified. Instead of input the file from command prompt check the code by specifying the file name in the code like:
String xmlFile = "C:\\data.xml";
If you got the error again,then send full error details.
Thanks
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|