473,787 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get Java to read in XML file and parse it against DTD?

When using Java to read in an XML file, I am having problems getting
the XML file to be parsed against the specified DTD.
Background:
I have an existing Java application that allows users to modify values
in a database.

To improve performance - we're looking to enable multiple record
modification by using XML files. The user downloads the required
records, changes them and uploads the modified file.

Issue:
I want to ensure that when we read the XML file in, it is parsed
against the specified DTD. The XML file includes the correct DTD. The
application throws FileNotFoundExc eption when the DTD cannot be found,
but that seems to be it. It doesn't compare the elements in the XML
file to the DTD.

Any help would be greatly appreciated

Stuart
Here is the code, XML & DTD

/**
* Java code
*/
import java.io.FileRea der;
import org.xml.sax.*;
import org.xml.sax.hel pers.*;

public class XML_Handler extends XMLFilterImpl {
public XML_Handler() {
super();
}

public static void readFile(java.i o.File f) {
System.out.prin tln("XML_Handle r.readFile");
try {
XMLReader xr = XMLReaderFactor y.createXMLRead er();
XML_Handler handler = new XML_Handler();
xr.setContentHa ndler(handler);
xr.setErrorHand ler(handler);
xr.setDTDHandle r(handler);

FileReader r = new FileReader(f);
xr.parse(new InputSource(r)) ;
} catch (Exception e) {
System.err.prin tln("XML_Handle r.readFile " + e);
e.printStackTra ce();
}
}

/**
* Additional code not included
*/
}
/**
* Example XML file
*/
<?xml version="1.0"?>
<!DOCTYPE poem SYSTEM "http://.../poem.dtd">
<poem>
<title>Title of the peom</title>
<l>line 1</l>
<l>line 2</l>
<line>line 3</line> <!-- this is an error -->
<l>line 4</l>
</poem>

/**
* Example DTD file: "http://.../poem.dtd"
*/
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT poem (title, l*)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT l (#PCDATA)>
Jul 20 '05 #1
0 3623

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4223
by: Michael | last post by:
Hello I am trying to write a Java-Program which converts a XML-file in a HTML. It should take the Transformation-file from the XML-file itself. Below find a possible XML-file: <?xml version="1.0" encoding="UTF-8"?> <!-- edited with XMLSPY v5 rel. 3 U (http://www.xmlspy.com) by Michael Herren (private) -->
5
14064
by: Aleksandar Matijaca | last post by:
Hi there, I am in some need of help. I am trying to parse using the apache sax parser a file that has vaid UTF-8 characters - I keep end up getting a sun.io.MalformedInputException error. This is my code:
133
8601
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
10
4273
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a circuit simulator, so I must first parse the netlist file. The program goes through an input file, and makes a hash_set of unique nodes (std::string's). The words are then sorted and numbered by copying the hash_set into a vector and sorting. ...
1
9654
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
0
1622
by: tumodav | last post by:
Hi friend, This tumodav. I have created a web service. I need to pass complex type of parameter. like from client side user can send user define datatype (ex. any class type object). it will create all interfaces and all other task. when I m going to depoye in JRun then it shoe me this error: D:\Program Files\Allaire\JRun\servers\axis\soap\WEB-INF\classes\ds\ws>java org.apache.axis .client.AdminClient -l...
2
3837
by: wolverine | last post by:
Hi, I recently read that every java .class file, is written in a specific binary format. http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html I just want to know whether there is any C++ class for extracting those structure information from a .class file . I am NOT speaking about decompiling the java class. I just want to parse and extract some information from the .class file.
0
3139
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the url,first it will ask for authentication.After giving username and password,the authentication will be confirmed and if the site has access right as allow,the website will open else a page will be displayed.There we can send request mail to the...
318
11138
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... http://kingrazi.blogspot.com/2008/05/shootout-c-net-vs-java-benchmarks.html Just to keep the post on topic for my friends at comp.lang.c++, how do I play default windows sounds with C++?
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.