setDoctype for outFormat does not work [message #256826] |
Wed, 21 May 2008 05:06  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 #257051 is a reply to message #256959] |
Sat, 24 May 2008 08:22  |
Eclipse User |
|
|
|
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
>
|
|
|
Powered by
FUDForum. Page generated in 0.45661 seconds