Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Delimiter for attributes in an element

Reply
Thread Tools

Delimiter for attributes in an element

 
 
Tim Streater
Guest
Posts: n/a
 
      04-28-2012
Take for example, this:

<a href="http://www.example.com" target="_blank">Click here</a>

Now, according to section 3.2.2 of:

<http://www.w3.org/TR/html401/intro/sgmltut.html>

the attributes are separated by spaces. Does it really mean this, or is
any whitespace allowed? IOW, could my example above be legally written
as:

<a href="http://www.example.com"
target="_blank">Click here</a>

I'd like to think the answer is no, it has to be space(s) (it would be
very irritating to find that any white space is permitted).

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
 
 
 
Beauregard T. Shagnasty
Guest
Posts: n/a
 
      04-28-2012
Tim Streater wrote:

> Take for example, this:
>
> <a href="http://www.example.com" target="_blank">Click here</a>


I realize that is just an example, but note that "Click here" as link
anchor text shouldn't be used in the real world.

<http://www.hallaminternet.com/blog/2011/07/the-click-here-problem.html>

> Now, according to section 3.2.2 of:
>
> <http://www.w3.org/TR/html401/intro/sgmltut.html>
>
> the attributes are separated by spaces. Does it really mean this, or is
> any whitespace allowed? IOW, could my example above be legally written
> as:
>
> <a href="http://www.example.com"
> target="_blank">Click here</a>
>
> I'd like to think the answer is no, it has to be space(s) (it would be
> very irritating to find that any white space is permitted).


After a short test, it seems to work (at least in Firefox 12), but might
be dependent on the browser's error correction. Best to use regular
spaces between the attributes. It also makes maintenance easier (to read).

--
-bts
-This space for rent, but the price is high
 
Reply With Quote
 
 
 
 
Tim Streater
Guest
Posts: n/a
 
      04-28-2012
In article <jnh4rn$gcn$(E-Mail Removed)>,
"Beauregard T. Shagnasty" <(E-Mail Removed)> wrote:

> Tim Streater wrote:
>
> > Take for example, this:
> >
> > <a href="http://www.example.com" target="_blank">Click here</a>

>
> I realize that is just an example, but note that "Click here" as link
> anchor text shouldn't be used in the real world.
>
> <http://www.hallaminternet.com/blog/2011/07/the-click-here-problem.html>


Of course not. That's why I always put "Click there". <runs away>

> > Now, according to section 3.2.2 of:
> >
> > <http://www.w3.org/TR/html401/intro/sgmltut.html>
> >
> > the attributes are separated by spaces. Does it really mean this, or is
> > any whitespace allowed? IOW, could my example above be legally written
> > as:
> >
> > <a href="http://www.example.com"
> > target="_blank">Click here</a>
> >
> > I'd like to think the answer is no, it has to be space(s) (it would be
> > very irritating to find that any white space is permitted).

>
> After a short test, it seems to work (at least in Firefox 12), but might
> be dependent on the browser's error correction. Best to use regular
> spaces between the attributes. It also makes maintenance easier (to read).


Well quite. That's why I didn't bother testing it.

I was enquiring because I do some elementary sanitising of html before
shoving it in an iframe. Changing all target attributes to _blank is
just one such, and I'd rather have to search for ' target'.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      04-28-2012
2012-04-28 18:50, Tim Streater wrote:

> Now, according to section 3.2.2 of:
>
> <http://www.w3.org/TR/html401/intro/sgmltut.html>
>
> the attributes are separated by spaces. Does it really mean this,


No. The section is sloppy language even for a tutorial, and it is
normatively relevant. Normatively, HTML 4.01 has been defined as an
application of SGML (though never really implemented that way - but it's
still *mostly* implemented in a roughly SGML-like manner, including this
issue).

In SGML, attribute specifications (that's what people normally mean by
"attribute" as a syntact construct) *may* be separated by any number of
whitespace characters. Technically, this is not defined in terms of
separators but so that an attribute specification list is just a
sequence of attribute specifications, and an attribute specification is
syntactically defined as starting and ending with s*, which means any
(possibly empty) sequence of whitespace.

Browsers play by these rules, though probably more by coincidence than
by willingness to implement SGML rules.

> or is
> any whitespace allowed?


Yes, including none.

> IOW, could my example above be legally written as:
>
> <a href="http://www.example.com"
> target="_blank">Click here</a>


Certainly, and also as
<a href="http://www.example.com"target="_blank">Click here</a>
(Few, if any, people would recommend that. But it is valid, as you can
check using a validator, and accepted by browsers.)

> I'd like to think the answer is no, it has to be space(s) (it would be
> very irritating to find that any white space is permitted).


I would find it irritating to find that any whitespace is *not*
permitted. In modern standards (largely, anything from the 1990s or
newer), the SPACE character seldom has a special role as a separator; it
is more common to define things in terms of whitespace characters.

In XHTML, things are different, but only in the sense that at least one
whitespace character is required between attribute specifications.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Tim Streater
Guest
Posts: n/a
 
      04-28-2012
In article <jnh9o8$eo3$(E-Mail Removed)>,
"Jukka K. Korpela" <(E-Mail Removed)> wrote:

> 2012-04-28 18:50, Tim Streater wrote:
>
> > Now, according to section 3.2.2 of:
> >
> > <http://www.w3.org/TR/html401/intro/sgmltut.html>
> >
> > the attributes are separated by spaces. Does it really mean this,

>
> No. The section is sloppy language even for a tutorial, and it is
> normatively relevant. Normatively, HTML 4.01 has been defined as an
> application of SGML (though never really implemented that way - but it's
> still *mostly* implemented in a roughly SGML-like manner, including this
> issue).
>
> In SGML, attribute specifications (that's what people normally mean by
> "attribute" as a syntact construct) *may* be separated by any number of
> whitespace characters. Technically, this is not defined in terms of
> separators but so that an attribute specification list is just a
> sequence of attribute specifications, and an attribute specification is
> syntactically defined as starting and ending with s*, which means any
> (possibly empty) sequence of whitespace.
>
> Browsers play by these rules, though probably more by coincidence than
> by willingness to implement SGML rules.
>
> > or is
> > any whitespace allowed?

>
> Yes, including none.
>
> > IOW, could my example above be legally written as:
> >
> > <a href="http://www.example.com"
> > target="_blank">Click here</a>

>
> Certainly, and also as
> <a href="http://www.example.com"target="_blank">Click here</a>
> (Few, if any, people would recommend that. But it is valid, as you can
> check using a validator, and accepted by browsers.)


Mmmm, I was afraid of this - and in particular the no-whitespace as in
your example. I *really* don't want to have to look at full-strength
parsing of the html I receive, just so I can ensure that all <a> contain
target="_blank".

Alternatively, is there a way to ensure that links in html in an iframe
always open in a new window?

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      04-29-2012
2012-04-29 0:57, Tim Streater wrote:

> Mmmm, I was afraid of this - and in particular the no-whitespace as in
> your example. I *really* don't want to have to look at full-strength
> parsing of the html I receive, just so I can ensure that all <a> contain
> target="_blank".


I don't quite see the point... if you receive HTML from somewhere, can't
you make your HTML provider ensure that your rules are enforced?

> Alternatively, is there a way to ensure that links in html in an iframe
> always open in a new window?


Put <base target="_blank"> into the <head> part. This will set a default
target attribute on all links (and can be overridden with target
attributes in individual links, such as target="_self").

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Tim Streater
Guest
Posts: n/a
 
      04-29-2012
In article <jnihk1$hui$(E-Mail Removed)>,
"Jukka K. Korpela" <(E-Mail Removed)> wrote:

> 2012-04-29 0:57, Tim Streater wrote:
>
> > Mmmm, I was afraid of this - and in particular the no-whitespace as in
> > your example. I *really* don't want to have to look at full-strength
> > parsing of the html I receive, just so I can ensure that all <a> contain
> > target="_blank".

>
> I don't quite see the point... if you receive HTML from somewhere, can't
> you make your HTML provider ensure that your rules are enforced?




The html is the bodies of emails. Need I say more?

> > Alternatively, is there a way to ensure that links in html in an iframe
> > always open in a new window?

>
> Put <base target="_blank"> into the <head> part. This will set a default
> target attribute on all links (and can be overridden with target
> attributes in individual links, such as target="_self").


Yes, I thought of <base>. Unfortunately all that does is supply a
default. If a link has an explicit target, that is the one used.

I think I'm going to try a slightly different approach. At present, the
sequence is:

SQLite db -> PHP sanitisation -> ajax -> JavaScript write to iframe.

I'll look at moving the sanitisation from PHP (where I have to deal with
the raw html) to after it's written into the iframe. That way I let the
browser make sense of the html first, after which I can fiddle with the
DOM.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xtml: combining attributes from one element into a different element Mike N. XML 3 03-17-2008 01:30 PM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
WebControl.Attributes.Add and custom attributes P4trykx ASP .Net 2 01-31-2007 04:33 PM
Parse reserved attributes as normal attributes Max XML 1 09-22-2006 12:04 PM
Query : Number of Attributes under an element & atleast 1 occurence of element/Attribute kosaraju.puneeth@gmail.com XML 0 10-26-2005 07:09 AM



Advertisments