File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Inserting node in XMl and retaining doc type information Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Inserting node in XMl and retaining doc type information" Watch "Inserting node in XMl and retaining doc type information" New topic
Author

Inserting node in XMl and retaining doc type information

Anoop Somasundaran
Greenhorn

Joined: Feb 28, 2008
Posts: 6
Hi All,

I want to insert one new node in an XML. Using the following code I can do that. But the problem is if the XML has doc type declaration then its giving me problem. After inserting the node the transformer is removing my doc type declaration from the XML. I have to retain the doc type definition (including entity declaration) as it is in the original XML file.

The following is the code that I�m using.



The doc type def. in the original file is some thing like this.



I know that I can set up the doc type definition in the new XML using the following properties of the transformer.

transformer.setOutputProperty( OutputKeys.DOCTYPE_SYSTEM,�article� ); transformer.setOutputProperty( OutputKeys.DOCTYPE_PUBLIC,�my DTD def�);

I cannot hard code the DTD def. as it can vary from one XML to another. Using doc.getDocType() I can get the doctype of the original XML. But is it is not returning the complete def. including entities declaration. Its giving me "someurl/TFJA.dtd".

Is there any way to retain the complete doc type in the original XML file? I don�t have much experience in XML and this issue is eating my head.. Also do I have to modify the DTD to accommodate the new tags added in order to make it a valid XML?

Any help and sample code would be highly appreciated.

Thanks,
Anoop S
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting node in XMl and retaining doc type information