Both Mike and Mattias are both correct. The XML declaration is exactly that, an XML declaration and it is not a processing instruction. It may look like a processing instruction though (one of XML's quirks).
 
So I take it that you are using document.asXML() or document.write(Writer) to turn the Document back into into XML text? If so, the only way to supress the XML declaration is to use the XMLWriter and OutputFormat(). The XML declaration is not really there, in a dom4j Document. It is just added by default in the asXML() or write() methods of Document.
 
Another option is to just output the root element and not the document.
 
Document doc = ...;
String theXML = doc.getRootElement().asXML();
 
Note that the above is a bit of a back and would loose any comments or processing instructions outside of the root element. for example consider this XML document, however for data-centric XML programs it could work.
 
<?xml version="1.0"?>
<?some-pi value="cheese"?>
<!-- a comment --->
 
<root>
  <bar/>
</root>
<!-- another comment -->
<?another-pi value="pizza"?>
----- Original Message -----
Sent: Friday, August 09, 2002 3:53 PM
Subject: RE: [dom4j-user] Processing Instruction problem with removeProcessingInstruction() method

Thank you so much but in my case on the fly dom4j document is getting generated and before displaying or storing it i need to remove xml declaration. I am not using XMLWriter and so OutputFormat. Is there any other way i could remove xml declaration from dom4j document directly instead of setSuppressDeclaration(true); ?

Thanks,

Vicky

 Mattias Reichel <[EMAIL PROTECTED]>wrote:

Hi,

The xml declaration is not a processing instruction.

So you cannot remove it this way.

 

Use the setSuppressDeclaration() method of OutputFormat and feed it to your XMLWriter constructor.

 

Cheers

/Mattias

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of JavaXML Developer
Sent: den 9 augusti 2002 14:03
To: [EMAIL PROTECTED]
Subject: [dom4j-user] Processing Instruction problem with removeProcessingInstruction() method

 

Hi All,

I badly need help to get removeProcessingInstruction() method wrok. If anybody could suggest me a solution, would highly be appreciated.

 


Do You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs



Do You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs

Reply via email to