XML DOM error

XML DOM error

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
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.

Thanks

Ads









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 (roseindia.net
javascript dom error-message
javascript dom error-message  javascript dom error-message
Advertisements
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
Version of com.globalmentor>globalmentor-xml-dom-impl dependency
List of Version of com.globalmentor>globalmentor-xml-dom-impl dependency
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
Maven Dependency globalmentor-xml-dom-impl >> 0.5.0
You should include the dependency code given in this page to add Maven Dependency of com.globalmentor >> globalmentor-xml-dom-impl version0.5.0 in your project
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"?> <
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
Maven dependency for com.globalmentor - globalmentor-xml-dom-impl version 0.6.5 is released. Learn to use globalmentor-xml-dom-impl version 0.6.5 in Maven based Java projects
of globalmentor-xml-dom-impl released The developers of   com.globalmentor - globalmentor-xml-dom-impl project have released the latest version of this library...-xml-dom-impl library is 0.6.5. Developer can use this version ( com.globalmentor
Maven dependency for com.globalmentor - globalmentor-xml-dom-impl version 0.6.4 is released. Learn to use globalmentor-xml-dom-impl version 0.6.4 in Maven based Java projects
of globalmentor-xml-dom-impl released The developers of   com.globalmentor - globalmentor-xml-dom-impl project have released the latest version of this library...-xml-dom-impl library is 0.6.4. Developer can use this version ( com.globalmentor
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
Error-
Error-   Hello, I would like to know about XSD file. I try to print XML file but I am getting error SAXException-- says Content is not allowed in prolog. Please help me
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
error
HelloWorld Deployment Error for module: HelloWorld: Error occurred during... [HelloWorld]. TargetNamespace.1 : Espace de noms "http://java.sun.com/xml/ns/j2ee...://java.sun.com/xml/ns/javaee'.. Please see server.log for more details. please help me
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
ModuleNotFoundError: No module named 'dom'
is throwing following error: ModuleNotFoundError: No module named 'dom' How to remove the ModuleNotFoundError: No module named 'dom' error...: No module named 'dom' error will be solved. Thanks
Dom in java
Create XML using DOM import java.io.*; 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
error
error  i have 404 error in my program plz tell me yhe solution about
error
error  i have 404 error in my program plz tell me yhe solution about
error
/ServletUserEnquiryForm.shtml getting an error given below SQLException caught: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error please suggest
Error
Error  I have created ajax with php for state and city. When I change state then city will not come in dropdown list and it give me error as 'Unknown Runtime Error'. This error come only in IE browser, but in other brower
error
error
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern

Ads