Discussion:
tags as attribute content
(too old to reply)
Jeff Chapman
2004-08-17 16:03:19 UTC
Permalink
Hi,

Is it legal in SGML or XML to include one or more tags as the value of an attribute?

For example:

<sometag attr="blah <tag> blah">....</sometag>

Thanks.
Tad McClellan
2004-08-17 22:15:32 UTC
Permalink
Post by Jeff Chapman
Is it legal in SGML or XML to include one or more tags as
the value of an attribute?
No.

Why do you think that you _want_ to put "tags" in attributes?
--
Tad McClellan SGML consulting
***@augustmail.com Perl programming
Fort Worth, Texas
Jeff Chapman
2004-08-18 12:03:30 UTC
Permalink
Post by Tad McClellan
Post by Jeff Chapman
Is it legal in SGML or XML to include one or more tags as
the value of an attribute?
No.
Why do you think that you _want_ to put "tags" in attributes?
Thanks Tad.

I didn't think it sounded like a good idea but a co-worker told me
that an SGML editor he was using allowed him to do this. I didn't
press him on why he wanted to do that or it's merits.
Tad McClellan
2004-08-18 12:37:03 UTC
Permalink
Post by Jeff Chapman
Post by Tad McClellan
Post by Jeff Chapman
Is it legal in SGML or XML to include one or more tags as
the value of an attribute?
No.
Why do you think that you _want_ to put "tags" in attributes?
Thanks Tad.
I didn't think it sounded like a good idea but a co-worker told me
that an SGML editor he was using allowed him to do this. I didn't
press him on why he wanted to do that or it's merits.
In

<sometag attr="blah <tag> blah">....</sometag>

There are only 2 tags: a start tag for the "sometag" element,
and an end tag for the same element.

There is an
angle bracket
t
a
g
angle bracket

sequence of characters in an attribute value, but it is not a "tag" (element).
--
Tad McClellan SGML consulting
***@augustmail.com Perl programming
Fort Worth, Texas
Charlie O
2004-08-18 20:56:38 UTC
Permalink
Post by Tad McClellan
No.
Why do you think that you _want_ to put "tags" in attributes?
--
Tad McClellan SGML consulting
Fort Worth, Texas
Tad,

Not as strange as you may think. I ran into this problem just today. I'm
in SGML support at a large aerospace company in your town. (guess who).
Had an author who used <emphasis> tags as part of an attribute value for
footnotes.

Epic and DL Composer simply view this as CDATA, so there are no parsing
errors.

Charlie O
Fort Worth, Texas
Tad McClellan
2004-08-18 22:59:15 UTC
Permalink
Post by Charlie O
Post by Tad McClellan
Why do you think that you _want_ to put "tags" in attributes?
Not as strange as you may think. I ran into this problem just today. I'm
in SGML support at a large aerospace company in your town. (guess who).
I worked there (I think) for twelve years.

That is where I learned my SGML (IETMs). :-)
Post by Charlie O
Had an author who used <emphasis> tags as part of an attribute value for
footnotes.
He has "forked" an element with a single name into 2 elements with
the same name. If they have different semantics then they should
have different names, else "spaghetti documents" will result.

He is dragging the Structured Markup back to the (more familiar?)
Word Processor way of thinking. :-(
Post by Charlie O
Epic and DL Composer simply view this as CDATA, so there are no parsing
errors.
Yes, I know.

The document model for the situation you describe contains a
bug nonetheless IMHO.



Note _my_ emphasis way above. :-)

The author kludged his way around a faulty design.

A sensible person should not _want_ elements inside of attributes.

When they think they want that, it is an indication that they
have made the wrong choice in the frequently discussed
"element vs. attribute" wars^H^H^H^H discussions.


http://www.oasis-open.org/cover/elementsAndAttrs.html
--
Tad McClellan SGML consulting
***@augustmail.com Perl programming
Fort Worth, Texas
David Carlisle
2004-08-19 11:31:42 UTC
Permalink
A sensible person should not _want_ elements inside of attributes.

When they think they want that, it is an indication that they
have made the wrong choice in the frequently discussed
"element vs. attribute" wars^H^H^H^H discussions.


true, but sometimes those choices were made by someone else, decades ago,
and requirements have changed.

For example the following HTML which works in mozilla or netscape (but
not in IE as it doesn't know the data: URI scheme)


<a href="data:text/html,some <b>marked up</b> <i>html</i> in an attribute.">hmmm</a>

Even without the data: scheme you often see this kind of thing in query
parameters after the ? in http URIs.

applet param attributes also often get passed such strings that are
intended to be understood as markup (eg passing in SVG or MathML or
whatever.

One could redesign HTML's href and param attributes to be child elements
instead, but even some "sensible people" might think that slipping in
some aesthetically dubious markup makes for a simpler life than trying
to update the browser on every machine on the planet...

David
Peter Flynn
2004-09-07 22:39:57 UTC
Permalink
David Carlisle wrote:
[quoting Tad]
Post by Tad McClellan
A sensible person should not _want_ elements inside of attributes.
Only Arvin has actually answered the OP's question (yes, < is allowed
in SGML CDATA attributes, but not in XML), but this highlights the
underlying problem.
Post by Tad McClellan
When they think they want that, it is an indication that they
have made the wrong choice in the frequently discussed
"element vs. attribute" wars^H^H^H^H discussions.
true, but sometimes those choices were made by someone else, decades ago,
and requirements have changed.
It is sometimes useful to be able to edit a document to correct it, but
retain the original (incorrect) markup in an SGML CDATA attribute for
other purposes. But it's rare outside scholarly applications like TEI,
and I'd rather see that kind of stuff in a comment anyway.

The difficulty is almost always poor DTD/Schema design, which fails to
cater for a requirement by the user to preserve some aspect of an earlier
version of the document in a form which will persist through processing
and which can later be reprocessed in a different manner. PIs can sometimes
help, but it still comes back to using the right data model for your DTD
or Schema, and that is something which requires skill and flexibility.

///Peter
--
"The cat in the box is both a wave and a particle"
-- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
Arvin Portlock
2004-08-18 16:49:35 UTC
Permalink
Post by Jeff Chapman
Hi,
Is it legal in SGML or XML to include one or more tags as the value of an attribute?
....
Thanks.
In SGML, < and > are legal within attributes but not in XML.
As has been pointed out, to an SGML parser these aren't tags,
just a sequence of characters that look to us like tags. A
project can choose to interpet them locally as if they were tags.
I have seen this done in some TEI encoding. E.g,

<list type="ordered">
<item n="1">Item 1</item>
<item n="<unclear>2</unclear>">Item 2</item>

In XML this would have to be encoded as: <list type="ordered"> <item n="1">Item 1</item> <item n="&lt;unclear&gt;2&lt;/unclear&gt;">Item 2</item>

and subject to local interpretation. TEI encoders often have
to worry about such minutiae. Whether or not one considers this
sort of encoding as a good idea is another matter entirely, but
it's out there.

Arvin
Loading...