[XOM-interest] XML pretty printer

Luca Passani passani at eunet.no
Sun Jul 29 04:06:44 EDT 2007


Thanks Elliotte, but it still does not work for me:

 > protected void writeEndTag(Element element) {
 >   super.writeEndTag(element);
 >   if (element.getLocalName().equals("device")) {
 >     breakLine();
 >   }
 > }

here is what I did:

package net.sourceforge.wurfl.wurflapi;

import nu.xom.*;
import java.io.*;

class WurflSerializer extends Serializer {

    WurflSerializer(OutputStream out) {
      super(out);
    }

    protected void writeEndTag(Element element) throws IOException {
      super.writeEndTag(element);
      if (element.getLocalName().equals("device")) {
          breakLine();
      }
    }
}

Invocation is now:

    WurflSerializer serializer = new WurflSerializer(out);

and the result is still the following (i.e. neither elements with a 
content nor singleton tags are correctly added a new line when the 
pretty printer outputs the tag). I upgraded to the latest jar from 
xom.nu to be sure:
        :
    </device>
    <device user_agent="LG-A7150 MIC/WAP2.0 Profile/MIDP-2.0 
Configuration/CLDC-1.1" fall_back="lg_a7150_ver1" 
id="lg_a7150_ver1_subaumic20"/>
    <device user_agent="LG-A7150 MIC/WAP2.0 
Profile/MIDP-2.0Configuration/CLDC-1.1" fall_back="lg_a7150_ver1" 
id="lg_a7150_ver1_subaumic20nospace"/>
    <device user_agent="LGE-AD5235" fall_back="uptext_generic" 
id="lge_ad5235_ver1"/>
    <device user_agent="LGE-AD5235/1.0 UP.Browser/4.1.26l" 
fall_back="lge_ad5235_ver1" id="lge_ad5235_ver1_sub4126"/>
    <device user_agent="LGE-AX3200" fall_back="uptext_generic" 
id="lge_ax3200_ver1"/>
    <device user_agent="LGE-AX3200 UP.Browser/4.1.26l" 
fall_back="lge_ax3200_ver1" id="lge_ax3200_ver1_sub4126"/>
    <!-- Meritxell Ceballos -->
    <device user_agent="LG-B1300" actual_device_root="true" 
fall_back="lg_generic" id="lg_b1300_ver1">
      <group id="product_info">
           :
      </group>
    </device>
    <device user_agent="LG-B2000".................

Luca

Elliotte Harold wrote:
> Luca Passani wrote:
>
>> Is there a way to fix this with the XOM serializer/pretty printer? of 
>> course, I only want th extra line to apply to the "device" element 
>> and not to others.
>
>
> When you pretty print, XOM assumes it can muck with the white space. 
> You could probably override writeEndTag to add an extra line after 
> certain elements. E.g.
>
> protected void writeEndTag(Element element) {
>   super.writeEndTag(element);
>   if (element.getLocalName().equals("device")) {
>     breakLine();
>   }
> }
>
>




More information about the XOM-interest mailing list