Can custom converters insert newline?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Can custom converters insert newline?

Andrew Norton

Hello,

 

I need my XML output to look like the following even if it isn’t “valid”.

 

                    <mchoice>

                                        <question>

                                                            Some data

                                        </question>

                                        <answer Correct="Yes">

                                                            Firewalking

                                        </answer>

                                        <answer Correct="No">

                                                            IDLE scanning

                                        </answer>

                                        <answer Correct="No">

                                                            Footprinting

                                        </answer>

                                        <answer Correct="No">

                                                            Enumeration

                                        </answer>

                                        <feedbackonincorrect>

                                                            Some data

                                        </feedbackonincorrect>

                    </mchoice>

 

I’ve tried to insert a newline in my marshal method of the custom converter that handles this object.  I can’t seem to get the desired solution. Any advice is very appreciated.

 

Thank you and Happy New Year!

 

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Can custom converters insert newline?

Jörg Schaible-2
Hi Andrew,

Andrew Norton wrote:

> Hello,
>
> I need my XML output to look like the following even if it isn't "valid".
>
>                     <mchoice>
>                                         <question>
>                                                             Some data
>                                         </question>
>                                         <answer Correct="Yes">
>                                                             Firewalking
>                                         </answer>
>                                         <answer Correct="No">
>                                                             IDLE scanning
>                                         </answer>
>                                         <answer Correct="No">
>                                                             Footprinting
>                                         </answer>
>                                         <answer Correct="No">
>                                                             Enumeration
>                                         </answer>
>                                         <feedbackonincorrect>
>                                                             Some data
>                                         </feedbackonincorrect>
>                     </mchoice>
>
> I've tried to insert a newline in my marshal method of the custom
> converter that handles this object.  I can't seem to get the desired
> solution. Any advice is very appreciated.

You cannot modify the format of the XML with a converter. That one handles
only "values". You can try with a derived PrettyPrintWriter:

====================== %< ====================
 class MyWriter extends PrettyPrintWriter {
   // ...
   protected void writeText(QuickWriter writer, String text) {
     endOfLine();
     super.writeText(writer, text);
     endOfLine();
   }
 }

 XStream xstream(new XppDriver() {
   public HierarchicalStreamWriter createWriter(Writer out) {
     return new MyWriter(out, getNameCoder());
   }
 });
 String xml = xstream.toXML(object);
====================== %< ====================

> Thank you and Happy New Year!

Cheers,
Jörg



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email