Share on Google+Share on Google+

XML DOM error
1 Answer(s)      7 years ago
Posted in : Java Beginners
import org.w3c.dom.*;
import javax.xml.parsers.*;

public class DOMCountElement{
public static void main(String[] args) {
try {
BufferedReader bf = new BufferedReader(new InputStreamReader(;
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.");
System.out.print("File not found!");
catch (Exception ex) {

the above program "To Count XML Element" was copied from this website ( but im getting a error like this... " Server returned HTTP response code: 503 for URL:" im using eclipse IDE.. please help me with this. Thank u


View Answers

February 9, 2010 at 2:59 PM

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.


Related Tutorials/Questions & Answers:
XML DOM error - Java Beginners
XML DOM error  import org.w3c.dom.*; import javax.xml.parsers....("xml Document Contains " + nodes.getLength() + " elements."); } else...); } } } the above program "To Count XML Element" was copied from this website (
XML Error checker and locater (DOM)
XML Error checker and locater (DOM)   ... and locate (line and column number) an error in your XML document using the DOM APIs.  The XML document follows some rules to check its syntax. 
DOM  Hi... I created an xml file through java by using DOM Now..I need to get the prompt for download when i clicked the button... I used downloadaction...for this But it didn't worked.. Its jus viewing the xml file
DOM  Hello.... I'm creating an xml file from java using DOM... from the database values... and saving it in a file But the created xml file..."),rs.getString("email")); } System.out.println("Xml File Created
DOM to SAX and SAX to DOM - XML
Java DOM to SAX and SAX to DOM  Simple API for XML and Document Object Model
javascript dom error-message
javascript dom error-message  javascript dom error-message
Java-XML-DOM  Hi! I need some help. I have to make java program that loads an xml file and from it builds DOM(later i will have to work with it - like using xpath in java find some value and replace it...). Since i'm new to java
DOM to SAX and SAX to DOM - XML
DOM SAX Parser Java  What is the Difference between SAX and DOM parsers
dom to xml string
dom to xml string  Hi, I am writing a program in java that reads... have save the dom document into xml file. How to convert dom to xml string... for converting DOM object into string data. Please check the thread dom to xml
XML DOM Tutorial
XML DOM Tutorial       W3C provides a standard called DOM (Document Object Model) for HTML & XML documents. DOM is also used as an interface for accessing and manipulating HTML & XML
DOM  package name for Document class?   Hi Friend, The package is known as dom api. For more information, visit the following links: Thanks
Read Complex XML using DOM/SAX Parser.
Read Complex XML using DOM/SAX Parser.  I have a XML file which is having two types of Items. I want to extract all details of a type only. My XML goes something like this <Movie> <Bollywood> <Actor> Shah Rukh
Question about parsing XML document with DOM in JAVA.
Question about parsing XML document with DOM in JAVA.  Hi, I need to parse a XML file witch has info about classes. So i have for each class to have... it with multiple for loops, one iside the other but it doesnt work. My XML is this below
java code to create xml document from DOM object
java code to create xml document from DOM object  Hey! After knowing the way we can create DOM objects and add elements to it-> then displaying it on the console ;is there a way I can output the same in xml document
DOM  hello, What is DOM?   hii, DOM is stands for Document object Model. DOM is an interface-oriented Application Programming Interface. We can use it for navigation of the entire document
Getting Dom Tree Elements and their Corresponding XML Fragments
Getting Dom Tree Elements and their Corresponding XML Fragments... will learn to get the elements of a DOM tree and their corresponding XML... the DOM tree elements and their corresponding XML fragments are displayed
Java XML Parsing Using DOM
Java XML Parsing Using SAX To Parse XML document using SAX parser method you need to follow the following steps. Consider the following XML file Students.xml <?xml version="1.0" encoding="UTF-8"?> <
deployment error - XML
getting the following error after i deployed my war file on tomcat.I suspecting my... web.xml entries to support spring and site mesh?? here is the error on my console and my web.xml ......... -------------------------------------- SEVERE: Error
Java DOM Tutorial
the  elements and its value using DOM APIs.  XML Error checker... and column number) an error in your XML document using the DOM APIs.  The XML.... The DOM is an interface that exposes an XML document as a tree structure
XML error message: The reference to entity
XML error message: The reference to entity   XML error message: The reference to entity "ai" must end with the ';' delimiter. Im getting this error when i gotta edit my blogger template Please advice manjunath
Reading xml file using dom parser in java with out using getelementby tag name
Reading xml file using dom parser in java with out using getelementby tag name  Hi, How to read the xml file using java with dom parser, but without...-Beginners/8384-java-with-xml-parsing.html but it is not reading attribute
XML Error Checking and Locating
XML Error Checking and Locating     ... in the XML document and error position.  Description of program: The following program helps you in checking and locating an error in XML document
Error after restart server... - XML
Error after restart server...  Hi, Im using Oracle JDeveloper 10g and Oracle SQL database.. Yesterday, the server team said they want to restart... app run perfectly... i got this error when i try to run my app:- 10/05/14
Example of getTagName() method in xml dom api.
the element. In this example, we create the Dom parser by create the instance of DocumentBuilder  using DocumentBuilderFactory . After parsing the xml file we
Parsing The XML File using DOM parser in JSP
Parsing The XML File using DOM parser in JSP... the DOM (Document Object Model) parser, that is the platform independent... the processing are displayed on to the present page. DOM parser is not an ideal
Document Object Model(DOM)
Document Object Model(DOM)       The Document Object Model (DOM) is a an standard object model that represents HTML or XML and related formats. Document Object Model is platform
Dom in java
Create XML using DOM import*; import org.w3c.dom.*; import...Dom in java  Exception in thread "main" org.w3c.dom.DOMException: INVALIDCHARACTERERR: An invalid or illegal XML character is specified
Creating Blank DOM Document
Creating Blank DOM Document       This tutorial shows you how to create blank DOM document. JAXP (Java API for XML Processing) is a Java interface that provides a standard
XML Parsing Error: mismatched tag. Expected: </br>. - JSP-Servlet
XML Parsing Error: mismatched tag. Expected: .  i had an error:"XML Parsing Error: mismatched tag. Expected: ." when uploading and writing them into an xml file. i use the jspBean to call the writeXML class. pls help me to solve
Java XML modification
Java XML modification This section explain you how to modify the xml file using DOM parser. For this purpose, you have to use DocumentBuilderFactory, DocumentBuilder and Document classes to get the default DOM parser and parse the xml
XML- read Text Mode - Java Error in Windows - reg. - Java Beginners
XML- read Text Mode - Java Error in Windows - reg.  Dear All I'm creating the code as read the XML file in BufferedReader method. Here I pasted the code below:. (*) First read the XML file using FileInputStream
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null