How to write an internal dtd with JAVA
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Peter_Lenson
Posted On:   Wednesday, February 19, 2003 08:13 PM

Hi there, This is probably a dumb question but; I having problems figuring out how to write an internal dtd using java. Let me explain, i create an xml file with an externally specified dtd as follows. File f = new File("file"); FileOutputStream fo = new FileOutputStream(f); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty("doctype-system", "erview.dtd"); t.transform( new DOMSource(doc), new StreamResult(fo)); fo.close(); This results in the following XML file.... <?xml version="1.0" encoding="UTF-8"?>   More>>

Hi there,



This is probably a dumb question but; I having problems
figuring out how to write an internal dtd using java.



Let me explain, i create an xml file with an externally
specified dtd as follows.


			
File f = new File("file");
FileOutputStream fo = new FileOutputStream(f);
Transformer t =
TransformerFactory.newInstance().newTransformer();
t.setOutputProperty("doctype-system", "erview.dtd");
t.transform( new DOMSource(doc),
new StreamResult(fo));
fo.close();


This results in the following XML file....

			
<?xml version="1.0" encoding="UTF-8"?>

5
5 108



What I want to do is write the contents of the
erview.dtd file to produce the following file:



			
<?xml version="1.0" encoding="UTF-8"?>

<!ELEMENT erview (Version|ProjectData|TableData|CommentData|LinkData)*> ] >
5
5 108


Thanks for any ideas
Peter    <<Less

Re: How to write an internal dtd with JAVA

Posted By:   Roseanne_Zhang  
Posted On:   Thursday, February 20, 2003 04:33 PM

In DOM level 2 specification, we have a DocumentType interface. However, it seems to be a read back result. Obviously, it does not have public constructors.


If it is a requirement, the easiest way to do the job is using text processing; add the text to the proper place of the XML file. This an ancient way to do things, but it is easy and efficient. Don't forget XML is also a text file! Even we have many fancy tools to work with it, the ancient way does still work. :-)

About | Sitemap | Contact