Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 20th, 2005, 10:55 AM
Michael Schuerig
Guest
 
Posts: n/a
Default Defining my own new attributes?


I would like to define additional attributes on some XHTML elements. The
purpose is to use them as parameters for scripts. So far, I have no
good grasp on how to add attributes *cleanly*. Of course, I can just
put them in, like this,

<input type="text" myns:maxlength="10" />

However, that's not valid XHTML. If possible, what I'd like to achieve
is this: I want to live in peace with XHTML validators by telling them
that they should just check the XHTML as they know it and when they
encounter an attribute with a specific prefix they should not complain
about it, but instead accepts that it is my business to look after the
attribute.

Michael

--
Michael Schuerig Airtight arguments have
mailto:michael@schuerig.de vacuous conclusions.
http://www.schuerig.de/michael/ --A.O. Rorty, Explaining Emotions

  #2  
Old August 20th, 2005, 01:05 PM
Nick Kew
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

Michael Schuerig wrote:[color=blue]
> I would like to define additional attributes on some XHTML elements. The
> purpose is to use them as parameters for scripts. So far, I have no
> good grasp on how to add attributes *cleanly*. Of course, I can just
> put them in, like this,
>
> <input type="text" myns:maxlength="10" />
>
> However, that's not valid XHTML. If possible, what I'd like to achieve
> is this: I want to live in peace with XHTML validators by telling them
> that they should just check the XHTML as they know it and when they
> encounter an attribute with a specific prefix they should not complain
> about it, but instead accepts that it is my business to look after the
> attribute.[/color]

You can't if you serve up pages like that. Serve them as XML rather
(x)html.

However, if you're serving them on the Web, you can deal with it
by negotiating with user agents. Strip out your extra attributes
(using the Apache namespace framework, or your server's equivalent)
when serving to a 'normal' client. Have clients that want your
namespace say so in an Accept: header, and negotiate based on that.

--
Nick Kew
  #3  
Old August 20th, 2005, 02:05 PM
Michael Schuerig
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

Nick Kew wrote:
[color=blue]
> Michael Schuerig wrote:[color=green]
>> I would like to define additional attributes on some XHTML elements.
>> The purpose is to use them as parameters for scripts. So far, I have
>> no good grasp on how to add attributes *cleanly*. Of course, I can
>> just put them in, like this,
>>
>> <input type="text" myns:maxlength="10" />
>>
>> However, that's not valid XHTML. If possible, what I'd like to
>> achieve is this: I want to live in peace with XHTML validators by
>> telling them that they should just check the XHTML as they know it
>> and when they encounter an attribute with a specific prefix they
>> should not complain about it, but instead accepts that it is my
>> business to look after the attribute.[/color]
>
> You can't if you serve up pages like that. Serve them as XML rather
> (x)html.[/color]

What exactly do you mean by "can't"? That it is not possible to achieve
valid XHTML in this way? Or that browsers won't be able to deal with
what they get?
[color=blue]
> However, if you're serving them on the Web, you can deal with it
> by negotiating with user agents. Strip out your extra attributes
> (using the Apache namespace framework, or your server's equivalent)
> when serving to a 'normal' client. Have clients that want your
> namespace say so in an Accept: header, and negotiate based on that.[/color]

My clients are ordinary current web browsers. Ideally they just ignore
attributes they don't know about. I'll handle them with JavaScript.

Michael

--
Michael Schuerig Thinking is trying to make up
mailto:michael@schuerig.de for a gap in one's education.
http://www.schuerig.de/michael/ --Gilbert Ryle

  #4  
Old August 20th, 2005, 02:15 PM
Henri Sivonen
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

In article <de7958$qkh$1@newsreader3.netcologne.de>,
Michael Schuerig <michael@schuerig.de> wrote:
[color=blue][color=green]
> > You can't if you serve up pages like that. Serve them as XML rather
> > (x)html.[/color]
>
> What exactly do you mean by "can't"? That it is not possible to achieve
> valid XHTML in this way?[/color]

If you add stuff that is not valid according to XHTML 1.0, XHTML 1.1 or
XHTML Basic, your document obviously won't be valid XHTML 1.0, XHTML 1.1
or XHTML Basic.

However, if you write your own schema, your document can be valid
according to that schema. You may be able to truthfully claim that your
language belongs in the "XHTML family".
[color=blue]
> Or that browsers won't be able to deal with
> what they get?[/color]

They'll deal by parsing the attribute into the DOM and not acting on the
attribute in any particular way.

--
Henri Sivonen
hsivonen@iki.fi
http://hsivonen.iki.fi/
Mozilla Web Author FAQ: http://mozilla.org/docs/web-developer/faq.html
  #5  
Old August 20th, 2005, 02:25 PM
Lachlan Hunt
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

Michael Schuerig wrote:[color=blue]
> Nick Kew wrote:
>
>[color=green]
>>Michael Schuerig wrote:
>>[color=darkred]
>>>I would like to define additional attributes on some XHTML elements.
>>>The purpose is to use them as parameters for scripts. So far, I have
>>>no good grasp on how to add attributes *cleanly*. Of course, I can
>>>just put them in, like this,
>>>
>>> <input type="text" myns:maxlength="10" />
>>>
>>>However, that's not valid XHTML. If possible, what I'd like to
>>>achieve is this: I want to live in peace with XHTML validators by
>>>telling them that they should just check the XHTML as they know it
>>>and when they encounter an attribute with a specific prefix they
>>>should not complain about it, but instead accepts that it is my
>>>business to look after the attribute.[/color]
>>
>>You can't if you serve up pages like that. Serve them as XML rather
>>(x)html.[/color][/color]

He didn't give any indication about how they were being served, so how
can you assume that he isn't serving them as XML?
[color=blue]
> What exactly do you mean by "can't"?[/color]

I believe he meant that you can't serve it as text/html, you need to use
an XML MIME type like application/xhtml+xml or application/xml.
[color=blue]
> That it is not possible to achieve valid XHTML in this way?[/color]

Well, it is possible, but you have to write your own DOCTYPE or schema
to validate against. However, you should understand that validity is
different from conformance and even though the document may pass
validation, it may not be conformant.

You should look into XHTML Modularisation, which allows you to extend
the langauge with your own modules.
[color=blue]
> My clients are ordinary current web browsers.[/color]

If that includes "current browsers" (read: obsolete) like IE, then you
can't do what you want because IE will not accept XHTML served with the
correct MIME type. If includes other browsers, such as Firefox, Opera
or nearly every other modern browser, then XHTML modularisation may be
suitable for your needs.

[color=blue]
> Ideally they just ignore attributes they don't know about. I'll
> handle them with JavaScript.[/color]

Your extensions (incluing, among other things, any elements or
attributes you add) will appear in the DOM, but browsers will not do
anything useful with them. Scripts and/or stylesheets will be able to
work with them like any other element or attribute.

--
Lachlan Hunt
http://lachy.id.au/
http://GetFirefox.com/ Rediscover the Web
http://GetThunderbird.com/ Reclaim your Inbox
  #6  
Old August 20th, 2005, 05:35 PM
Michael Schuerig
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

Lachlan Hunt wrote:
[color=blue]
> Michael Schuerig wrote:[/color]
[color=blue]
> I believe he meant that you can't serve it as text/html, you need to
> use an XML MIME type like application/xhtml+xml or application/xml.[/color]

What happens if I serve such a document as text/html nevertheless?
Presumably the browser won't burst into flames.
[color=blue]
> You should look into XHTML Modularisation, which allows you to extend
> the langauge with your own modules.[/color]

Yes, that's what I guessed, but my knowledge of modularization is less
than superficial. Are there any more approachable documents on the
topic than the W3C recommendations?

Apparently I need to write my own schema as an extension of a suitable
existing XHTML schema. I can't remember seeing any information on how
to do this, unfortunately.
[color=blue][color=green]
>> My clients are ordinary current web browsers.[/color]
>
> If that includes "current browsers" (read: obsolete) like IE, then you
> can't do what you want because IE will not accept XHTML served with
> the
> correct MIME type.[/color]

As much as I like it, I can't ignore IE. But again the question, what
bad things happen if I do serve a document with a technically incorrect
MIME type?

Michael

--
Michael Schuerig The more it stays the same,
mailto:michael@schuerig.de The less it changes!
http://www.schuerig.de/michael/ --Spinal Tap, The Majesty of Rock

  #7  
Old August 20th, 2005, 05:55 PM
James Pickering
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

Michael Schuerig wrote:
[color=blue]
> As much as I like it, I can't ignore IE. But again the question, what
> bad things happen if I do serve a document with a technically incorrect
> MIME type?[/color]

If you serve XHTML 1.0 as (Markup validated) text/html your document
should render and display the same as a (Markup validated) HTML 4.01
document; it will not have XML functionality -- you need to serve XHTML
1.0 as application/xhtml+xml for that.

XHTML 1.1 and XHTML Basic documents should only be served as
application/xhtml+xml.

--
James Pickering
http://www.jp20.org/

  #8  
Old August 20th, 2005, 06:15 PM
James Pickering
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?


Previously I wrote:
[color=blue]
> If you serve XHTML 1.0 as (Markup validated) text/html your document
> should render and display the same as a (Markup validated) HTML 4.01
> document; it will not have XML functionality -- you need to serve XHTML
> 1.0 as application/xhtml+xml for that.
>
> XHTML 1.1 and XHTML Basic documents should only be served as
> application/xhtml+xml.[/color]

Of course, MSIE browsers do not recognize MIME type
application/xhtml+xml and will display a download window when served
such documents -- this is the old dilemna -- you are really better off
creating valid HTML 4.01 documents.

James Pickering
http://www.jp29.org/ (corrected)

  #9  
Old August 20th, 2005, 06:55 PM
Michael Schuerig
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

James Pickering wrote:
[color=blue]
>
> Previously I wrote:
>[color=green]
>> If you serve XHTML 1.0 as (Markup validated) text/html your document
>> should render and display the same as a (Markup validated) HTML 4.01
>> document; it will not have XML functionality -- you need to serve
>> XHTML 1.0 as application/xhtml+xml for that.
>>
>> XHTML 1.1 and XHTML Basic documents should only be served as
>> application/xhtml+xml.[/color]
>
> Of course, MSIE browsers do not recognize MIME type
> application/xhtml+xml and will display a download window when served
> such documents -- this is the old dilemna -- you are really better off
> creating valid HTML 4.01 documents.[/color]

Yes, but that doesn't help me with my original problem. I'm looking for
a way to attach additional payload to my markup. What I'm currently
doing is that I'm abusing the class attribute, where I add classes of
the form <key>:<url-encoded-value>. It works, it's conformant, as the
class attribute is defined as a cdata-list. But it is ugly and doesn't
feel right.

Michael

--
Michael Schuerig Thinking is trying to make up
mailto:michael@schuerig.de for a gap in one's education.
http://www.schuerig.de/michael/ --Gilbert Ryle

  #10  
Old August 20th, 2005, 07:05 PM
Henri Sivonen
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

In article <de7lr0$grg$1@newsreader3.netcologne.de>,
Michael Schuerig <michael@schuerig.de> wrote:
[color=blue]
> Lachlan Hunt wrote:
>[color=green]
> > Michael Schuerig wrote:[/color]
>[color=green]
> > I believe he meant that you can't serve it as text/html, you need to
> > use an XML MIME type like application/xhtml+xml or application/xml.[/color]
>
> What happens if I serve such a document as text/html nevertheless?
> Presumably the browser won't burst into flames.[/color]

At worst your choice of doctype might lead to the quirks layout mode
(assuming "such document" means a document which is like an Appendix C
XHTML 1.0 doc except it has a home-grown attribute somewhere).
[color=blue]
> Apparently I need to write my own schema as an extension of a suitable
> existing XHTML schema. I can't remember seeing any information on how
> to do this, unfortunately.[/color]

Instead of DTDs, you may prefer to use RELAX NG. Either way, your result
will be unofficial.

The easiest way is to grab a full copy of an existing schema and edit
the parts you need changed.

--
Henri Sivonen
hsivonen@iki.fi
http://hsivonen.iki.fi/
Mozilla Web Author FAQ: http://mozilla.org/docs/web-developer/faq.html
  #11  
Old August 20th, 2005, 07:15 PM
David Håsäther
Guest
 
Posts: n/a
Default Re: Defining my own new attributes?

James Pickering <jp29@cox.net> wrote:
[color=blue]
> If you serve XHTML 1.0 as (Markup validated) text/html your
> document should render and display the same as a (Markup
> validated) HTML 4.01 document[/color]

In your favorite browser maybe.

--
David Håsäther
 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles