Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inserting node in XMl and retaining doc type information  RSS feed

Anoop Somasundaran
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Anoop S
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!