XML DOM error

Ads
 

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
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
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
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
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
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
Java Write To File Dom Document
Java Write To File Dom Document In this tutorial you will learn how to write to file dom document. Write to xml file you would be required to use the package javax.xml. This package provides the facility to create XML file easily
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
ModuleNotFoundError: No module named 'ais-dom'
, ModuleNotFoundError: No module named 'ais-dom' error will be solved...ModuleNotFoundError: No module named 'ais-dom'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ais
ModuleNotFoundError: No module named 'ais-dom'
, ModuleNotFoundError: No module named 'ais-dom' error will be solved...ModuleNotFoundError: No module named 'ais-dom'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ais
ModuleNotFoundError: No module named 'dom-query'
python library, ModuleNotFoundError: No module named 'dom-query' error...ModuleNotFoundError: No module named 'dom-query'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'glance_dom'
;glance_dom' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'glance_dom'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'snag-dom'
library, ModuleNotFoundError: No module named 'snag-dom' error...ModuleNotFoundError: No module named 'snag-dom'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named
Insert XML file data to database
Insert XML file data to database In this tutorial, you will learn how to insert the xml file data to database using dom parser. You all are aware of XML... ()); } } } Description Of Code: In this example, we have used DOM interface to read an xml
XML
XML  How i remove a tag from xml and update it in my xml
DOM paring problem
DOM paring problem  Hi My code always show arrayindexoutofbound here is my code i am using arraylist to display and DOM parser to retrieve XML value. I am searching the value by attributes equals 2. this error i am getting
DOM paring problem
DOM paring problem  Hi My code always show arrayindexoutofbound here is my code i am using arraylist to display and DOM parser to retrieve XML value. I am searching the value by attributes equals 2. this error i am getting
Javascript DOM
generate a fixture list. I was knocking about using DOM techniques but with minimal
Java dom from string
Java dom from string  Hi, How to create dom tree from string data? I am trying to search the example for java dom from string. Thanks   ...://www.roseindia.net"; String strData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
xml
xml  why the content written in xml is more secure
xml
xml  validate student login using xml for library management system

Ads