[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Guidelines for handling of elements' content?


xml spacing


Ralf wrote:
> ...
> This content contains both the xml user content (i.e. the "real" 
> content) and the xml text file "format" content.
> My real question is how do I use that content? How do I design my XML?
> How do I know that the spacing matters, or that the \n matters or are 
> just a byproduct of the XML text file?
> Is it best to remove all spacing and \n after and before any kind of 
> non-whitespace content?
> Sure xml:space tells me I should preserve them or not... really? The 
> specs doesn't tell me much about it. It just says the application gets 
> it all or knows what to do with it. Well personnally I don't. What about 
> "good behavior" guidelines for applications?
> 
> Here I'm dealing with SVG (typically <text> and <tspan>) but I already 
> had the problem with other custom xml formats.]
> 
> A typical example that confuses me:
> 
> <text>    this
>   is a text   .
>     </text>
> 
> What should I interpret here? One straight line, one line with one \n in 
> the middle, or one with thre \n ? What about the spaces before "is" and 
> "this"?

The only whitespace that can really be in question is whitespace between 
elements - that is, between the end of one element and the start of the 
next.  Whitespace in element content is simply part of the content and 
is not to be removed.  Whitespace is allowed between elements for visual 
formatting, and it is a sensible question to ask about how to tell when 
such whitespace is just for formatting and when it is actually supposed 
to be part of the content.

That's one of the things that a DTD or schema is supposed to answer.  Of 
course, if there is no DTD there is no way to be certain (except for 
xml:space).  If an element allows mixed content, then any whitespace 
between its child elements would have to be considered part of the 
element's content.  Conversely, if no PCDATA is allowed, then any 
whitespace between elements would have to be for visual formatting only.

When there is a DTD or schema is involved, you only get this whitespace 
knowledge passed on if the processor is set for validation.

You can tell the processor more specifically what you have in mind with 
the xml:space attribute.  Again, it applies just to whitespace between 
the end of one element and the start of another.

If xml:space is not specified, you will generally get the processor's 
default behavior, which is application-dependent.

To recap, all the PCDATA in your example "text" element should be handed 
to your code as is, and ther is no need for you to try to figure out 
what it "should" be like.

And, BTW, there is no "\n" in xml, which does not know about such idioms 
from certain programming languages.  In a processed XML document, you 
will have &#10; characters where you originally had newlines.

Cheers,

Tom P



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.