Christian,

I agree with your reading of the documentation of createPrettyPrint. However, it
was doing *more* than what it said it was doing.
Here's my element (for example):
<sensors>
BlueSensors
</sensors>

createPrettyPrint *should* produce (according to the documentation):
<sensors>BlueSensors</sensors>

but instead, I get:
<sensors/>

createPrettyPrint stripped my content, and the documentation clearly states that
it should not do that, and I don't believe that is what was intended. It does
this for elements that have embedded newlines. createPrettyPrint works fine if
the whitespace is only spaces, for example:
<sensors>       BlueSensor    </sensor>

So maybe my definition of whitespace was incorrect? From the XML Schema Part 2:
Datatypes W3C Recommendation 02 May 2001(partial):
"4.3.6 whiteSpace

       [Definition:]   whiteSpace constrains the ·value space· of types
·derived· from string such that the
       various behaviors specified in Attribute Value Normalization in [XML 1.0
(Second Edition)] are
       realized. The value of whiteSpace must be one of {preserve, replace,
collapse}.

       preserve
           No normalization is done, the value is not changed (this is the
behavior required by [XML 1.0
           (Second Edition)] for element content)
       replace
           All occurrences of #x9 (tab), #xA (line feed) and #xD (carriage
return) are replaced with #x20
           (space)
    collapse
           After the processing implied by replace, contiguous sequences of
#x20's are collapsed to a
           single #x20, and leading and trailing #x20's are removed. "


I assumed createPrettyPrint would be *collapsing* as defined. However, this may
all be moot, as I recalled an earlier email regarding a possible bug in
XMLWriter, so that when I retrieved the latest daily build my problem went away!
I apologize for speaking too soon.

thanx
steve

"Christian Holmqvist, IT, Posten" wrote:

> Se documentation for createPrettyPrint:
>
> ---
> public static OutputFormat createPrettyPrint()
> A static helper method to create the default pretty printing format. This
> format consists of an indent of 2 spaces, newlines after each element and
> all other whitespace trimmed, and XMTML is false.
> ---
>
> This is doing exactly how it should be doing.
>
> If you want to strip your element text of whitespace I would suggest that
> you either do a walker that moves throw your document and removes the
> whitespace. Or create your own implementation of the node that should ignore
> whitespace (i.e. element).
>
> Cheers Christian
>
> > -----Ursprungligt meddelande-----
> > Från: Stephen C. Upton [mailto:[EMAIL PROTECTED]]
> > Skickat: den 8 oktober 2002 03:37
> > Till: dom4j
> > Ämne: [dom4j-user] Bug or feature?
> >
> >
> > I read in the first snippet (identified by INPUT below) using
> > SAXReader
> > (both with setStripWhitespaceText to true and false). I then write out
> > using XMLWriter with createPrettyPrint OutputFormat. I get the snippet
> > identified below OUTPUT. Seems that the text of the elements that have
> > newlines embedded in the element text get deleted along with the
> > newlines. Obviously not what I want (well, maybe not obvious ;-)
> >
> > Suggestions?
> >
> > thanx
> > steve
> > p.s. this was my workaround to an earlier question about stripping
> > whitespace within an element.
> > *********
> > INPUT
> > ***********
> >     <agent>
> >  <name> blueDude </name>
> >  <side> BLUE </side>
> >  <sensors>
> >           BlueSensor
> >         </sensors>
> >       <commDevices>
> >           Blue1
> >         </commDevices>
> >  <movement>
> >           BlueMovement
> >         </movement>
> >  <decisions>
> >    viewSensors
> >    movement
> >  </decisions>
> >  <movementComponents>
> >           BlueMovementComponents
> >         </movementComponents>
> >       <commInterval> 20.0 </commInterval>
> >  <sentiment>BlueSentiment</sentiment>
> >  <refData>BlueReference</refData>
> >     </agent>
> > ************
> > OUTPUT
> > **********
> > <agent>
> >     <name>blueDude</name>
> >     <side>BLUE</side>
> >     <sensors/>
> >     <commDevices/>
> >     <movement/>
> >     <decisions/>
> >     <movementComponents/>
> >     <commInterval>20.0</commInterval>
> >     <sentiment>BlueSentiment</sentiment>
> >     <refData>BlueReference</refData>
> >   </agent>
> > ***********
> >
> >
> >
> >
> > -------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > dom4j-user mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/dom4j-user
> >




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to