Re: Whitespace in XML content

Bjoern Hoehrmann <[email protected]>
Newsgroups gmane.comp.web.html-tidy.devel
Message-ID <[email protected]>
* Sarah Wilkin wrote:
>I'm curious what the procedure is for adding new flags to the tidy  
>options. For example, I'm interested in a "xml preserve whitespace" or  
>a general "preserve whitespace" flag (where the developer would strip  
>unwanted whitespace afterwards while walking the tree).

The XML pretty printer (and maybe even the general XML parsing code) is
subject to a number of problems that make it indeed unusable for general
purpose XML processing. It is generally difficult for Tidy to do the
right thing for arbitrary XML documents with respect to whitespace, some
formats might desire that the white-space in

  <foo> <bar/> </foo>

is preserved, others might wish that for

  <foo><bar/></foo>

no white-space is added, you might want to keep

  <foo>x  x</foo>

with two spaces rather than one and so on. The issue you pointed out is
probably one of the top three reported bugs (of which at least one is
not a bug...), yet no one provided a patch to fix the problem, so this
is generally considered low priority. There are better processors out
there to deal with such cases and it is generally recommended to use
other tools.

Regarding new configuration options, such changes are best discussed on
this list, a proposal with a name, possible values and a description of
the exact impact is usually most helpful. Along with a patch to imple-
ment the described behavior :-)

>Of course the best change would be to evaluate whitespace in xml  
>differently than it is in html, purging only the whitespace used as  
>spacing between element tags. Since tidy has such a strong html focus  
>this would require a much bigger change in the source then merely  
>preserving all whitespace.

Well, I think there is some subtle bug somewhere, Tidy should generally
be able to process white-space as desired. Whether its object model in-
cludes white-space is controlled through GetToken() arguments, whether
and how white-space occurs in serialized output depends on the pretty
printer which has similar general purpose means which are set properly
for HTML/XHTML elements using the element tables. I would suspect that
in some place improper values are passed to the corresponding routines.

Tidy should generally have better means to control cleanup and presen-
tation, I've proposed a style sheet like facility using XPath to se-
lect elements, etc. you would have something like

  //pre                 { white-space: pre  }  /* preserve all ws  */
  //p[not(* or text())] { strip:       deep }  /* strip subtree    */
  //xmp                 { rename:      pre  }  /* <xmp> => <pre>   */
  //body                { ident:       0    }  /* don't ident body */
  ...

Or whatever. So, if we ever make major changes to the current model, I
would strongly suggest to think along these lines.
-- 
Björn Höhrmann · mailto:[email protected] · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.