Skip to main content



      Home
Home » Newcomers » Newcomers » setDoctype for outFormat does not work
setDoctype for outFormat does not work [message #256826] Wed, 21 May 2008 05:06 Go to next message
Eclipse UserFriend
Originally posted by: sanchita.sarkar.in.bosch.com

I am trying to create a xml file.I need to attach a doctype also.
Adding Encoding,version using outFormat works.
I have tried using setDoctype method of outFormat,but that does not work.


Code snippet :

probeMsgSerializer = new XMLSerializer();
strWriter = new StringWriter();
outFormat = new OutputFormat();

// Setup format settings
outFormat.setEncoding(XML_ENCODING);
outFormat.setVersion(XML_VERSION);
outFormat.setDoctype("TestPublic", "TestSystem");

outFormat.setIndenting(true);
outFormat.setIndent(4);


// Define a Writer
probeMsgSerializer.setOutputCharStream(strWriter);

// Apply the format settings
probeMsgSerializer.setOutputFormat(outFormat);

// Serialize XML Document
probeMsgSerializer.serialize(xmlDoc);
this.xmlStr = strWriter.toString();
strWriter.close();

................


Please suggest ,if anything is wrong in the code.

Is there anything wrong in
Re: setDoctype for outFormat does not work [message #256901 is a reply to message #256826] Wed, 21 May 2008 11:39 Go to previous messageGo to next message
Eclipse UserFriend
This really isn't an Eclipse question. Assuming that you're using the
Apache XMLSerializer, you should probably post the question there. If
you are using the com.sun....XMLSerializer class, you need to stop now
and rethink what you're trying to do (it's not part of the portable Java
API).

In the past, I've used the DocumentBuilderFactory and TransformerFactory
to achieve what you're attempting. A quick search on Google found this:

http://www.roseindia.net/xml/dom/CreatXMLFile.shtml

HTH,

Wayne

On Wed, 2008-05-21 at 09:06 +0000, sarkar wrote:
> I am trying to create a xml file.I need to attach a doctype also.
> Adding Encoding,version using outFormat works.
> I have tried using setDoctype method of outFormat,but that does not work.
>
>
> Code snippet :
>
> probeMsgSerializer = new XMLSerializer();
> strWriter = new StringWriter();
> outFormat = new OutputFormat();
>
> // Setup format settings
> outFormat.setEncoding(XML_ENCODING);
> outFormat.setVersion(XML_VERSION);
> outFormat.setDoctype("TestPublic", "TestSystem");
>
> outFormat.setIndenting(true);
> outFormat.setIndent(4);
>
>
> // Define a Writer
> probeMsgSerializer.setOutputCharStream(strWriter);
>
> // Apply the format settings
> probeMsgSerializer.setOutputFormat(outFormat);
>
> // Serialize XML Document
> probeMsgSerializer.serialize(xmlDoc);
> this.xmlStr = strWriter.toString();
> strWriter.close();
>
> ...............
>
>
> Please suggest ,if anything is wrong in the code.
>
> Is there anything wrong in
>
>
>
Re: setDoctype for outFormat does not work [message #256959 is a reply to message #256901] Thu, 22 May 2008 02:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sanchita.sarkar.in.bosch.com

Hello Wayne,
Thanks for your quick response.

I tried out with transformerfactory also.


TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "PUBLIC");
transformer.setOutputProperty(OutputKeys.ENCODING, "iso-8859-1");
transformer.setOutputProperty(OutputKeys.VERSION, "1.0");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);


Output is

<?xml version="1.0" encoding="iso-8859-1" standalone="no"?><math
xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>f(1)</mi><mo>=</mo></mrow><mrow><mi>f(2) </mi><mo>=</mo></mrow></math>


But still doctype is not added.

Thanks and Regards,
sarkar
Re: setDoctype for outFormat does not work [message #257051 is a reply to message #256959] Sat, 24 May 2008 08:22 Go to previous message
Eclipse UserFriend
I suggest that you take this question to one of the many XML forums.

Sorry, wish we could have helped more.

Wayne

On Thu, 2008-05-22 at 06:29 +0000, sarkar wrote:
> Hello Wayne,
> Thanks for your quick response.
>
> I tried out with transformerfactory also.
>
>
> TransformerFactory transformerFactory =
> TransformerFactory.newInstance();
> Transformer transformer = transformerFactory.newTransformer();
> transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "PUBLIC");
> transformer.setOutputProperty(OutputKeys.ENCODING, "iso-8859-1");
> transformer.setOutputProperty(OutputKeys.VERSION, "1.0");
> DOMSource source = new DOMSource(doc);
> StreamResult result = new StreamResult(System.out);
> transformer.transform(source, result);
>
>
> Output is
>
> <?xml version="1.0" encoding="iso-8859-1" standalone="no"?><math
> xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>f(1)</mi><mo>=</mo></mrow><mrow><mi>f(2) </mi><mo>=</mo></mrow></math>
>
>
> But still doctype is not added.
>
> Thanks and Regards,
> sarkar
>
Previous Topic:need James Lynch's document on ARM
Next Topic:Using Swing's Frame with SWT-Project included
Goto Forum:
  


Current Time: Wed Jul 16 12:56:12 EDT 2025

Powered by FUDForum. Page generated in 0.45661 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top