473,471 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

May a CDATA section appear in an attribute value?

Out of curiosity, may a CDATA section appear within an attribute
value with datatype CDATA? And if so, how about other attribute
value datatypes which accept the XML markup characters?

To me, the XML specification seems a little ambiguous on this, so
I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all
hinges on if CDATA attribute values are part of markup or not.)

Thanks.

Jon
Nov 23 '05 #1
10 42910
As I understand from the XML 1.0 spec, attribute value is a kind of a
literal which cannot start with ...<... or ...&...(unless it's a
reference). So, the answer is "no".

Regards,
-murat

Nov 23 '05 #2
Jon Noring wrote:
Out of curiosity, may a CDATA section appear within an attribute
value with datatype CDATA?
No. You can't have declaration markup in attribute values.
And if so, how about other attribute
value datatypes which accept the XML markup characters?
No attribute types allow element or declaration markup in their values.
To me, the XML specification seems a little ambiguous on this,
No, it's quite specific: Production 41, Well-Formedness Constraint:
"No < in Attribute Values"
I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all
hinges on if CDATA attribute values are part of markup or not.)


It doesn't really have anything at all to do with CDATA attribute
values. There is an unfortunately (hereditary) semantic distinction
between what CDATA means in attribute declarations and what CDATA
means in Marked Sections, which you probably don't want to investigate
unless you're a masochist (but it doesn't even have much to do with
that either :-)

It's a restriction in XML that you cannot have the open-angle bracket
in an attribute value. Period. Not for any reason. (You *could* do
this in SGML, but this was one of the sacrifices we had to make to
get a more extensible and easily-programmed language).

If you could give us some idea of what you wanted this for, perhaps
there is another way to solve the problem.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Nov 23 '05 #3
Peter Flynn answered:
Jon Noring asked:
Out of curiosity, may a CDATA section appear within an attribute
value with datatype CDATA?

... No, it's quite specific: Production 41, Well-Formedness
Constraint: "No < in Attribute Values"

It's a restriction in XML that you cannot have the open-angle
bracket in an attribute value. Period. Not for any reason. (You
*could* do this in SGML, but this was one of the sacrifices we had
to make to get a more extensible and easily-programmed language).
Thanks! Somehow I missed that particular well-formedness constraint
given in production 41. This constraint clearly trumps any other
ambiguities that there may be about using a CDATA section within
attribute values. No question about it -- CDATA sections must not
appear in attribute values.

Now, to address a slightly different issue, in my reading of that
constraint, it seems like the "<" character may not literally appear
(not as part of any markup) in an attribute value, whether directly
encoded, as a numeric character reference, or as part of a defined
general entity. It leaves out the ability of XML document authors to
use that character, in a literal fashion, within attribute values of
datatype CDATA. For example, this appears to not be allowed (where
"<" == "&#x003C;"):

<header title="Is A &#x003C; B?"> ... </header>

If you could give us some idea of what you wanted this for, perhaps
there is another way to solve the problem.


I don't have a particular problem. Rather it's simply trying to gain
a thorough understanding of using CDATA sections in XML documents
from an XML document authoring perspective.

But since you mention it, I am curious to know how an XML document
author may include the literal "<" character in a CDATA attribute
value. As noted above, it does not appear it is possible. Assuming
this indeed is the case, then the only way I can think of to get
around this would be to use a similar Unicode character. For example,
from the Unicode Basic Latin script chart the following are similar
characters:

x2039 single left-pointing angle quotation
x2329 left-pointing angle bracket
x27E8 mathematical left angle bracket
x3008 left angle bracket

But this kludge is still not very satisfying and has presentational
issues.

Thanks.

Jon Noring

Nov 23 '05 #4
Jon Noring wrote:
But since you mention it, I am curious to know how an XML document
author may include the literal "<" character in a CDATA attribute
value. As noted above, it does not appear it is possible.


<WAG>
Convert to an HTML entity? E.G. < = &lt;
</WAG>
Nov 23 '05 #5
Andrew Thompson wrote:
Jon Noring wrote:
But since you mention it, I am curious to know how an XML document
author may include the literal "<" character in a CDATA attribute
value. As noted above, it does not appear it is possible.

<WAG>
Convert to an HTML entity? E.G. < = &lt;
</WAG>


My prior message noted what the XML 1.0 Spec seems to say about
putting a literal "<" character into an attribute value: it appears
that it can't be done, even with an entity reference.

Here's the relevant section in XML 1.0:

http://www.w3.org/TR/REC-xml/#sec-starttags

Which says:

"Well-formedness constraint: No < in Attribute Values

"The replacement text of any entity referred to directly or
indirectly in an attribute value MUST NOT contain a <."
Now, being a little dense at times, maybe I'm misinterpreting what
the XML spec is saying, but it seems to me that the "<" character may
*never* appear in the attribute value of a well-formed XML document no
matter how it is done, encoded, directly and indirectly.

Am I right?

Jon
Nov 23 '05 #6
In article <ef********************************@4ax.com>,
Jon Noring <jo*@noring.name> wrote:
"The replacement text of any entity referred to directly or
indirectly in an attribute value MUST NOT contain a <."


The replacement text of the lt attribute is < which does
not contain a <. Note that < is a character reference,
not an entity reference. You can also use < directly in
attributes.

-- Richard
Nov 23 '05 #7
Richard Tobin wrote:
Jon Noring wrote:
"The replacement text of any entity referred to directly or
indirectly in an attribute value MUST NOT contain a <."

The replacement text of the lt attribute is < which does
not contain a <. Note that < is a character reference,
not an entity reference. You can also use < directly in
attributes.


Yes, the XML spec does note that a numeric character reference is not
an entity, nor is "&lt;", which is called a "string" even though its
structure suggests an entity reference.

In addition, the original 1998 XML spec, in rule 41, specifically
notes the following:

"The replacement text of any entity referred to directly or
indirectly in an attribute value (other than "&lt;") must not
contain a <."

So, the original intent was to allow "&lt;" to represent the "<"
character in attribute values (and by section 2.4 also allow the
numeric character reference of &#x003C; / < ). Tim Bray
commented on the above constraint in his well-known Annotated XML
Specification: http://www.xml.com/axml/notes/NoLTinAtt.html

"Banishing the < ... This rule might seem a bit unnecessary, on
the face of it. Since you can't have tags in attribute values,
having an < can hardly be confusing, so why ban it?

"This is another attempt to make life easy for the DPH ["Desperate
Perl Hacker"]. The rule in XML is simple: when you're reading text,
and you hit a <, then that's a markup delimiter. Not just
sometimes, always. When you want one in the data, you have to use
&lt;. Not just sometimes, always. In attribute values too.

"This rule has another unintended beneficial side-effect; it makes
the catching of certain errors much easier. Suppose you have a
chunk of XML as follows:

<a href="notes.html> <img src='notes.gif'></a>

"Notice that the notes.html is missing its closing quote. Without
the no-&lt; rule, it would be really hard to detect this problem
and issue a reasonable error message. Since attribute values can
contain almost anything, no error would be detected until the
processor finds the next quotation mark. Instead, you get an error
message the first time you hit a <, which in the example above, as
in many cases, is almost immediately."
So, from the possibilities list I previously posted:

1) <foo bar="is x < y ?">

2) <foo bar="is x &lt; y ?">

3) <foo bar="is x &#x003C; y ?">

4) <foo bar="is x &lessthan; y ?"

a) where in the DTD we have <!ENTITY lessthan "<">

b) where in the DTD we have <!ENTITY lessthan "&lt;">

c) where in the DTD we have <!ENTITY lessthan "&#x003C;">
It would seem like all are permissable except for #1 and #4a since
they involve the literal "<" character.

Am I right on this?

Thanks.

Jon
Nov 23 '05 #8
Jon Noring wrote:
Peter Flynn answered:
Jon Noring asked:
Out of curiosity, may a CDATA section appear within an attribute
value with datatype CDATA?
... No, it's quite specific: Production 41, Well-Formedness
Constraint: "No < in Attribute Values"

It's a restriction in XML that you cannot have the open-angle
bracket in an attribute value. Period. Not for any reason. (You
*could* do this in SGML, but this was one of the sacrifices we had
to make to get a more extensible and easily-programmed language).


Thanks! Somehow I missed that particular well-formedness constraint
given in production 41. This constraint clearly trumps any other
ambiguities that there may be about using a CDATA section within
attribute values. No question about it -- CDATA sections must not
appear in attribute values.


It's more fundamental than that: CDATA sections are for enclosing
pieces of your document *text* that contain markup characters < and &
that you do not want to be interpreted as markup. For example:

<para>To create the header of your web page, type the following:</para>
<programlisting><![CDATA[
<html>
<head>
<title>My first web page</title>
</head>
]]></programlisting>

I'm curious to know how the question could arise of such data appearing
in an attribute value. It's always very helpful to documentation writers
to understand the thought-processes or reading experiences that lie
behind people's acquisition of knowledge, because it's something that
rarely comes to light, and it can help make documentation more useful.
(If you have the time to explain...offline :-)
Now, to address a slightly different issue, in my reading of that
constraint, it seems like the "<" character may not literally appear
(not as part of any markup) in an attribute value,
Correct.
whether directly
encoded, as a numeric character reference, or as part of a defined
general entity.
The restriction is only on the literal < character itself. The character
entity reference &lt; and the decimal or hexadecimal equivalent are
perfectly valid in CDATA attribute values (indeed some document types
actually rely on this).
It leaves out the ability of XML document authors to
use that character, in a literal fashion, within attribute values of
datatype CDATA. For example, this appears to not be allowed (where
"<" == "&#x003C;"):

<header title="Is A &#x003C; B?"> ... </header>
No, that's perfectly valid. So is title="Is A&lt;C" (assuming lt is
declared, either explicitly or implicitly).

As I mentioned, SGML allowed markup start characters in attributes,
so <header title="Is A<C; B?">...</> would be OK in SGML. But to make
it easier to write software for XML this feature was withdrawn in XML.
If you could give us some idea of what you wanted this for, perhaps
there is another way to solve the problem.


I don't have a particular problem. Rather it's simply trying to gain
a thorough understanding of using CDATA sections in XML documents
from an XML document authoring perspective.


OK...the objective is as above: to stop the parser from interpreting
markup characters as markup. In a CDATA section, < and & are just
text.
But since you mention it, I am curious to know how an XML document
author may include the literal "<" character in a CDATA attribute
value.


As &lt; or the numeric equivalent.

///Peter

Nov 23 '05 #9
Peter Flynn wrote:
[explaining about the issue of "<" in attribute values]
Peter, thanks! You've clarified the issue very well. Very
valuable information.

Jon
Peter Flynn wrote:
[explaining about the issue of "<" in attribute values
in two separate messages.]


Peter, thanks! You've clarified the issue very well. Very
valuable information.

Jon
Nov 23 '05 #10
In article <se********************************@4ax.com>,
Jon Noring <jo*@noring.name> wrote:
So, from the possibilities list I previously posted:

1) <foo bar="is x < y ?">

2) <foo bar="is x &lt; y ?">

3) <foo bar="is x &#x003C; y ?">

4) <foo bar="is x &lessthan; y ?"

a) where in the DTD we have <!ENTITY lessthan "<">

b) where in the DTD we have <!ENTITY lessthan "&lt;">

c) where in the DTD we have <!ENTITY lessthan "&#x003C;">
It would seem like all are permissable except for #1 and #4a since
they involve the literal "<" character.


4c is also illegal, because character references (unlike entity
references) are expanded at entity definition time, so the replacement
text of lessthan contains a real "<" character.

This would be legal: <!ENTITY lessthan "&#x003C;"> since its
replacement text is "&#x003c;".

-- Richard
Nov 23 '05 #11

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

Similar topics

0
by: Douha | last post by:
Hi all, I have an XML file where all to elements for the data are contained in CDATA sections. I have a schema created that is working right now although it is pretty dumbed down. I have a need...
6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
4
by: troppfigo | last post by:
I have this example of xml <?xml version="1.0"?> <xml> <!]> </xml> I want to extract the contained data from <body> tag using an xslt transformation. I want to obtain this
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
2
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL...
4
by: werD | last post by:
Hello, Ive been reading about cdata-section-elements b/c ive got a comments field that id like to inlcude some html in. For some reason the final output is not including any cdata tags though?...
2
by: Pugi! | last post by:
Using AJAX I want to send some information from the server (php-page) as XML to the client. The contents can be very divers so I have to use XML instead of text. On one occasion the contents is...
2
by: viepia | last post by:
Hi, How would I edit the code below to read XML CData text? Thanks, Viepia XDocument connectedPCsXML = XDocument.Load(new...
1
!NoItAll
by: !NoItAll | last post by:
The MSXML parser is choking on a single character that often appears in my data within a CDATA section. Try this: Dim bRet As Boolean Dim lRet as long Dim xmlDoc As MSXML2.DOMDocument Set...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.