By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,867 Members | 1,964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,867 IT Pros & Developers. It's quick & easy.

Replacing name with id

P: n/a
I have a bunch of old web pages now in HTML 4.01 Strict I update every
now and then with revised material. They were written back when using <a
name=" was the normal method of including an anchor. Most of the
internal anchors follow a very standard layout, and are associated with
an h3 heading.

I was wondering whether there was any reason not to change these <a
name=" anchors to <h3 id=" anchors? I gather that all recent browsers
work fine with id on any element as an anchor. I also gather that name
is deprecated in one or another of the XHTML versions I am not yet using
due to IE. I did think it might be handy in future to be a little closer
to XHTML, if I do decide I am tired of catering to IE.

I would be making other global changes to all the pages, so this change
simply adds another few sets of global replacements to my work.

--
http://www.ericlindsay.com
Jan 6 '08 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Scripsit Eric Lindsay:
I was wondering whether there was any reason not to change these <a
name=" anchors to <h3 id=" anchors?
Not really, unless you're doing some scripting that needs id attributes
for the elements.
I gather that all recent browsers
work fine with id on any element as an anchor.
Right. We can virtually ignore Netscape 4 these days.
I also gather that name
is deprecated in one or another of the XHTML versions
That's irrelevant. (Technically, it's deprecated for <aelements, but
not for all elements. The reason for the deprecation, as you know, is
that the id attribute is more logical and XML-like for the purpose.)
I did think it might be handy in future to be a
little closer to XHTML, if I do decide I am tired of catering to IE.
It doesn't matter. If you ever switch to XHTML, you will have several
changes to be made anyway, and making _this_ change is not really
special. You might use id for new pages, just as you might use
lowercase-only element names, because these are allowed in classic HTML
as well as required in XHTML. But changing existing <a name= ...>
anchors or existing use of uppercase in element names is just pointless.
_Any_ change, no matter how automated, involves a risk of errors; some
assumptions may just fail, and your regular expression (or whatever) may
somehow miss some special case and produce a mess. It's better to take
risks only when there is something to be won, i.e. when performing the
(full) conversion to XHTML for some real reason.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jan 6 '08 #2

P: n/a
Sun, 06 Jan 2008 14:45:14 +1000 from Eric Lindsay
<NO*************@ericlindsay.com>:
I have a bunch of old web pages now in HTML 4.01 Strict I update every
now and then with revised material. They were written back when using <a
name=" was the normal method of including an anchor. Most of the
internal anchors follow a very standard layout, and are associated with
an h3 heading.

I was wondering whether there was any reason not to change these <a
name=" anchors to <h3 id=" anchors?
I can't think of any. IIRC, a very old version of Netscape honored
name= but not =id, but that's been quite a few years now. Just be
careful in your script to remove the associated </a>, even if it's
not on the same line.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Jan 6 '08 #3

P: n/a
Scripsit Jukka K. Korpela:
Scripsit Eric Lindsay:
>I was wondering whether there was any reason not to change these <a
name=" anchors to <h3 id=" anchors?

Not really, unless you're doing some scripting that needs id
attributes for the elements.
Oops, I seem to have misread the question. I answered the question "in
there any reason...".

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jan 6 '08 #4

P: n/a
In article <MP************************@news.individual.net> ,
Stan Brown <th************@fastmail.fmwrote:
Sun, 06 Jan 2008 14:45:14 +1000 from Eric Lindsay
I was wondering whether there was any reason not to change these <a
name=" anchors to <h3 id=" anchors?

I can't think of any. IIRC, a very old version of Netscape honored
name= but not =id, but that's been quite a few years now. Just be
careful in your script to remove the associated </a>, even if it's
not on the same line.
Many thanks. That old Netscape was probably what I was recalling as a
possible reason not to make the changes.

Thanks for mentioning the associated </a>. I did handle that correctly,
for once. The first few sets of changes I made did reveal that some of
my earlier pages were less like the later ones than I originally
expected. Perils of not using a program to generate my web pages.

There were some errors. The mess that Jukka (correctly) predicted did
occur, however only visible in a dozen or so pages. I had no doubt I
would find other flaws when I validated some of the pages again.

The big error was that id can not start with a number, and all my names
were actually automatically generated dates like 20080107a 20080107b and
so on. I wonder why that did not throw up a validation error when I had
<a name="20080107a" I had never noticed that I had thousands of such
name errors.

I can certainly see why Jukka cautions against taking risks with regular
expression changes over heaps of files. However I only seem to improve
by running up against vast numbers of my past errors.

--
http://www.ericlindsay.com
Jan 7 '08 #5

P: n/a
Mon, 07 Jan 2008 22:34:17 +1000 from Eric Lindsay
<NO*************@ericlindsay.com>:
The big error was that id can not start with a number, and all my names
were actually automatically generated dates like 20080107a 20080107b and
so on. I wonder why that did not throw up a validation error when I had
<a name="20080107a" I had never noticed that I had thousands of such
name errors.
I used similar names to anchor revision points in my pages. When I
switched to IDs I got the same validation errors you did, so I
prepended a U to them.

I remember researching the issue, but it was a few years ago. I can't
remember whether names starting with numerics were legal in name=, or
were illegal but just not found by the validator.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Jan 8 '08 #6

P: n/a
Stan Brown wrote:
>
I can't
remember whether names starting with numerics were legal in name=, or
were illegal but just not found by the validator.
http://www.w3.org/TR/html401/types.html#type-id

I don't know if the validator ever checked values on the name attribute,
though.
--
Berg
Jan 8 '08 #7

P: n/a
in comp.infosystems.www.authoring.html, Stan Brown wrote:
Mon, 07 Jan 2008 22:34:17 +1000 from Eric Lindsay
<NO*************@ericlindsay.com>:
The big error was that id can not start with a number, and all my names
<a name="20080107a" I had never noticed that I had thousands of such
When I switched to IDs I got the same validation errors you did, so I
prepended a U to them.
Which then breaks all external links.

--
Lauri Raittila <http://www.iki.fi/lr>
Jan 9 '08 #8

P: n/a
Stan Brown wrote:
Mon, 07 Jan 2008 22:34:17 +1000 from Eric Lindsay
<NO*************@ericlindsay.com>:
>The big error was that id can not start with a number, and all my names
were actually automatically generated dates like 20080107a 20080107b and
so on. I wonder why that did not throw up a validation error when I had
<a name="20080107a" I had never noticed that I had thousands of such
name errors.

I used similar names to anchor revision points in my pages. When I
switched to IDs I got the same validation errors you did, so I
prepended a U to them.

I remember researching the issue, but it was a few years ago. I can't
remember whether names starting with numerics were legal in name=, or
were illegal but just not found by the validator.
No a NAME and ID must start with a letter [A-Z,a-z]

http://www.w3.org/TR/html4/types.html#type-name

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jan 9 '08 #9

P: n/a
Lauri Raittila wrote:
in comp.infosystems.www.authoring.html, Stan Brown wrote:
>Mon, 07 Jan 2008 22:34:17 +1000 from Eric Lindsay
<NO*************@ericlindsay.com>:
>>The big error was that id can not start with a number, and all my names
<a name="20080107a" I had never noticed that I had thousands of such
>When I switched to IDs I got the same validation errors you did, so I
prepended a U to them.

Which then breaks all external links.
How? If www.example.com/somepage.html#00021 is a invalid URL

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jan 9 '08 #10

P: n/a
in comp.infosystems.www.authoring.html, Jonathan N. Little wrote:
Lauri Raittila wrote:
in comp.infosystems.www.authoring.html, Stan Brown wrote:
Mon, 07 Jan 2008 22:34:17 +1000 from Eric Lindsay
<NO*************@ericlindsay.com>:
The big error was that id can not start with a number, and all my names
<a name="20080107a" I had never noticed that I had thousands of such
When I switched to IDs I got the same validation errors you did, so I
prepended a U to them.
Which then breaks all external links.
How? If www.example.com/somepage.html#00021 is a invalid URL
But it works. Sure it would be better to have done it correctly in first
place, but why fix something that has been working before, especially
when side effect is to break something?

--
Lauri Raittila <http://www.iki.fi/lr>
Jan 9 '08 #11

P: n/a
Lauri Raittila wrote:
in comp.infosystems.www.authoring.html, Jonathan N. Little wrote:
>Lauri Raittila wrote:
>>in comp.infosystems.www.authoring.html, Stan Brown wrote:
Mon, 07 Jan 2008 22:34:17 +1000 from Eric Lindsay
<NO*************@ericlindsay.com>:
The big error was that id can not start with a number, and all my names
<a name="20080107a" I had never noticed that I had thousands of such
When I switched to IDs I got the same validation errors you did, so I
prepended a U to them.
>>Which then breaks all external links.
>How? If www.example.com/somepage.html#00021 is a invalid URL

But it works. Sure it would be better to have done it correctly in first
place, but why fix something that has been working before, especially
when side effect is to break something?
It "works" because of the browser's error correction, but no guarantee
that it will continue to work or with every browser. Anyway what is the
big deal? The situation only applies to the fragment, the external links
will still connect to the proper page. As long as you have reasonable
sized pages and not one of those "scroll-o-death" pages, folks will find
the info. What you don't want to beak is the link to the page.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jan 9 '08 #12

P: n/a
..oO(Jonathan N. Little)
>Stan Brown wrote:
>I remember researching the issue, but it was a few years ago. I can't
remember whether names starting with numerics were legal in name=, or
were illegal but just not found by the validator.

No a NAME and ID must start with a letter [A-Z,a-z]

http://www.w3.org/TR/html4/types.html#type-name
In most cases the 'name' attribute is of type CDATA, not NAME.

Micha
Jan 9 '08 #13

P: n/a
Michael Fesser wrote:
.oO(Jonathan N. Little)
>Stan Brown wrote:
>>I remember researching the issue, but it was a few years ago. I can't
remember whether names starting with numerics were legal in name=, or
were illegal but just not found by the validator.
No a NAME and ID must start with a letter [A-Z,a-z]

http://www.w3.org/TR/html4/types.html#type-name

In most cases the 'name' attribute is of type CDATA, not NAME.

Micha
"For some HTML 4 attributes with CDATA attribute values, the
specification imposes further constraints on the set of legal values for
the attribute that may not be expressed by the DTD."

....

"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".")."
--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jan 9 '08 #14

P: n/a
Wed, 9 Jan 2008 17:23:07 +0200 from Lauri Raittila
<la***@raittila.cjb.net>:
in comp.infosystems.www.authoring.html, Stan Brown wrote:
Mon, 07 Jan 2008 22:34:17 +1000 from Eric Lindsay
<NO*************@ericlindsay.com>:
The big error was that id can not start with a number, and all my names
<a name="20080107a" I had never noticed that I had thousands of such
When I switched to IDs I got the same validation errors you did, so I
prepended a U to them.

Which then breaks all external links.
I'm not going to shed any tears over that. The anchors were to
various passages modified on particular dates, and the only place it
makes sense to reference them is from the change log, which is on the
same page.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Jan 9 '08 #15

P: n/a
Michael Fesser wrote:
.oO(Jonathan N. Little)
>Michael Fesser wrote:
>>.oO(Jonathan N. Little)

Stan Brown wrote:

I remember researching the issue, but it was a few years ago. I can't
remember whether names starting with numerics were legal in name=, or
were illegal but just not found by the validator.
No a NAME and ID must start with a letter [A-Z,a-z]

http://www.w3.org/TR/html4/types.html#type-name
In most cases the 'name' attribute is of type CDATA, not NAME.

Micha
"For some HTML 4 attributes with CDATA attribute values, the
specification imposes further constraints on the set of legal values for
the attribute that may not be expressed by the DTD."

Correct. But are there such constraints mentioned in the spec regarding
the 'name' attribute on anchors? Sections 12.2 and 12.2.1 say nothing
about the allowed chars (except for using only ASCII chars) or what kind
of char the name should start with.

Then there's also 12.2.3, which says:

| Because of its specification in the HTML DTD, the name attribute may
| contain character references. Thus, the value D&#xfc;rst is a valid
| name attribute value, as is D&uuml;rst . The id attribute, on the
| other hand, may not contain character references.
True but the still does not allow a NAME or ID to begin with [0-9]

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jan 10 '08 #16

P: n/a
..oO(Jonathan N. Little)
>Michael Fesser wrote:
>>
Then there's also 12.2.3, which says:

| Because of its specification in the HTML DTD, the name attribute may
| contain character references. Thus, the value D&#xfc;rst is a valid
| name attribute value, as is D&uuml;rst . The id attribute, on the
| other hand, may not contain character references.

True but the still does not allow a NAME or ID to begin with [0-9]
Yes, but the 'name' attribute of an anchor is not a NAME token, it's a
CDATA. So the question remains, whether a name starting with a digit is
valid or not.

For me it doesn't matter anyway, it's just out of interest.

Micha
Jan 10 '08 #17

This discussion thread is closed

Replies have been disabled for this discussion.