473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

whitespace in element content

Hello,

it is often convenient to insert whitespace into an XML document in order to
format it nicely. For example, take this snippet of a notional DocBook XML
document:

<para>
This is a longer paragraph.
With <wordasword>lon ger</wordasword> I mean that it contains more than
one sentence.
</para>

I want the whitespace in this snippet of code to be handled as follows:

(1) The whitespace between "<para>" and "This" as well as the whitespace
between "sentence." and "</para>" shall be discarded.

(2) Each other sequence of adjacent whitespace characters shall be
transformed into a single space character.

But how do XML processors and applications deal with this issue?

In section 2.10 of "Extensible Markup Language (XML) 1.0 (Third Edition)",
one can read:

In editing XML documents, it is often convenient to use "white
space" (spaces, tabs, and blank lines) to set apart the markup for
greater readability. Such white space is typically not intended for
inclusion in the delivered version of the document.

But who decides which whitespace shall be considered as whitespace that is
just used to set apart the markup? And is whitespace just used to indent
lines of text also not intended for inclusion in the delivered version?
What is this "delivered version" of the document?

I'd be thankful for any clarification.

Best whishes,
Wolfgang
Jul 20 '05 #1
2 2164
In article <2u************ *@uni-berlin.de>,
Wolfgang Jeltsch <je*****@tu-cottbus.de> wrote:
But who decides which whitespace shall be considered as whitespace that is
just used to set apart the markup? And is whitespace just used to indent
lines of text also not intended for inclusion in the delivered version?
What is this "delivered version" of the document?
As far as the XML spec is concerned, deciding which whitespace is
significant or not is a job for the application, which really means
"everything except the parser". A conformant parser must give all the
whitespace to the application, which can then decide what to do with
it.

Of course, there may be other standard programs or libraries layered
on top of the XML parser which you might not consider to be the
application. XSLT for example allows you to specify that some
whitespace is to be stripped from its input. From the point of view
of the parser, XSLT is the application, but you may regard it as just
a library that you're using.
I want the whitespace in this snippet of code to be handled as follows:

(1) The whitespace between "<para>" and "This" as well as the whitespace
between "sentence." and "</para>" shall be discarded.

(2) Each other sequence of adjacent whitespace characters shall be
transformed into a single space character.


This is a fairly common form of whitespace normalization and often
goes under the name of "tokenizati on". For example, XML itself treats
tokenized attributes like this. Among other things, you could use an
XML Schema processor to do this normalization.

-- Richard
Jul 20 '05 #2

"Wolfgang Jeltsch" <je*****@tu-cottbus.de> wrote in message
news:2u******** *****@uni-berlin.de...
Hello,

it is often convenient to insert whitespace into an XML document in order
to
format it nicely. For example, take this snippet of a notional DocBook
XML
document:

<para>
This is a longer paragraph.
With <wordasword>lon ger</wordasword> I mean that it contains more
than
one sentence.
</para>

I want the whitespace in this snippet of code to be handled as follows:

(1) The whitespace between "<para>" and "This" as well as the
whitespace
between "sentence." and "</para>" shall be discarded.

(2) Each other sequence of adjacent whitespace characters shall be
transformed into a single space character.

But how do XML processors and applications deal with this issue?

In section 2.10 of "Extensible Markup Language (XML) 1.0 (Third Edition)",
one can read:

In editing XML documents, it is often convenient to use "white
space" (spaces, tabs, and blank lines) to set apart the markup for
greater readability. Such white space is typically not intended for
inclusion in the delivered version of the document.

But who decides which whitespace shall be considered as whitespace that is
just used to set apart the markup? And is whitespace just used to indent
lines of text also not intended for inclusion in the delivered version?
What is this "delivered version" of the document?

I'd be thankful for any clarification.

my parser uses what could be called the "newline whitespace assertion",
namely:
any initial whitespace is ignored;
any whitespace following a newline is eaten and replaced with a single space
(unless it is the end of the text).
<foo>Hello World
Again</foo>

is parsed as:
<foo>Hello World Again</foo>

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4482
by: Wired Earp | last post by:
I've had some luck using string values "\t" "\n" and "\r" to insert tabs, newlines and carriagereturn textnodes into a document, but I can't *read* these nodes, at least not by analyzing the nodeValue. Am i missing something? /** * NodeFilter supposed to remove ignorable whitespace */ private class WhiteSpaceFilter implements NodeFilter {
8
2938
by: Tjerk Wolterink | last post by:
Hello all, how does xsl handle white space? I know you can set domething like this for nice indentation: <xsl:output method="xhtml" indent="yes"/> But know i have xsl code like this:
7
13347
by: Georg J. Stach | last post by:
Hi, as mentioned above I'd like to validate a simple XML-document with a simple DTD. For this, I use Java and Xerces. But, when I have tags of this form: <tag>some characters in here</tag> Xerces always complains with:
0
1293
by: Daniel Cazzulino [MVP XML] | last post by:
Hi guys, I need an attribute (could be an element too) to have its whitespace collapsed . I don't get the expected behavior, however. The schema is as follows: <xs:schema ...> <xs:element name="Root"> <xs:complexType> <xs:sequence /> <xs:attribute name="Tokenize">
4
497
by: Larry | last post by:
I believe the .Net XmlValidatingReader should fail when validating XML that contains a ComplexType element with white space when the ComplexType element has the mixed attribute set to false in the XSD used for validation. XSD fragment: <xs:element name="TRSellerBuyerData"> <xs:complexType mixed="false"> <xs:sequence>
0
1395
by: SimonDev | last post by:
Hi I've got an unusual problem I'm hoping someone could advise me on, regarding the formatting of the body of an HTTP response from a web service. We are using HTTP POST rather than SOAP for calling web methods to save network traffic over a cellular network. Each web method returns an XmlDocument with a <resproot element. Most web methods simply return a single value as the content of the <respelement (integer or string). However...
9
2555
by: amattie | last post by:
Does anyone have any idea on how I can strip the extra whitespace in the XML that shows up when I receive a response from an ASP.NET 2.0 webservice? This has been discussed before, but no one has ever come up with a good answer to what seems like such a common question. ...
1
1582
by: andrew_nuss | last post by:
Hi, Lets say I have a MIXED tag in my XML DTD with content that is going to be rendered as HMTL, as well as a <boldand <italicstag. What about whitespace? Specifically, does the whitespace in PCDATA of the MIXED tag get rendered into the output html? Or is it a setting in the XSL transforming document? Thanks, Andy
5
3907
by: John Gordon | last post by:
My XSLT files have many occurrences of this general pattern: <a> <xsl:attribute name="href"> <xsl:value-of select="xyz" /> </xsl:attribute> </a> When I execute an XSL transform, the resulting HTML looks like this:
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.