473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Adding custom attributes through XMLSchema

Hi, I want to add custom attributes to my xhtml documents to use with
my DOM scripts.
For example, I want to have some tags -say, the <h1>- have an attribute
[ replaceable="true" ] and a [ replace-with="../images/main-title.png"
].

The thing is that I also want the document to validate against xhtml
1.1 :-)

How can I define a Schema (and embed it in my xhtml) to expand XHTML
default and add this custom attributes?

So far I have been trying to follow W3Schools Schema Tutorial [
http://www.w3schools.com/schema/schema_schema.asp ] but something tells
me that it won't work with XHTML (besides the fact that tidy -the
extension for firefox, at least- doesn't validate).

Thanks,
#foca

Nov 5 '05 #1
8 2157
ni*****************@gmail.com wrote:
Hi, I want to add custom attributes to my xhtml documents to use with
my DOM scripts.
That's not useful in WWW authoring. How could you know whether some browser
somewhere recognizes the attributes as meaning something - and most probably
something completely different than you have in your mind?
For example, I want to have some tags -say, the <h1>- have an attribute
[ replaceable="true" ] and a [ replace-with="../images/main-title.png"
].
Why would you scatter such presentational data around your HTML document?
Using class="replaceable" id="main-title" should be sufficient your purposes.
You can have the mapping from id values to image URLs as a table in your
script code. Much cleaner.
The thing is that I also want the document to validate against xhtml
1.1 :-)
So you want to conform to a syntactic specification and not conform to it?

Besides, XHTML 1.1 is unsuitable for use on the WWW now and in the
foreseeable future. If you _know_ that you have some tangible benefits from
playing with XML, use XHML 1.0, otherwise use the good old HTML 4.01.
How can I define a Schema
A schema would not help you to validate against XHTML 1.1.
So far I have been trying to follow W3Schools Schema Tutorial


W3Schools is known for its many errors. Proceed with special care if you use
it.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Nov 5 '05 #2
On 4 Nov 2005 18:55:20 -0800, ni*****************@gmail.com wrote:
Hi, I want to add custom attributes to my xhtml documents


Don't use XHTML documents on the web, or if you do, present them as
text/html instead of XML (as described in Appendix C). Although "the
web" will happily consume XHTML documents today, it's not practical to
serve them as XML - almost nothing will make use of these XML features
and it is more likely to cause trouble than to be a benefit.

It's questionable to do this with XHTML 1.1, so abandon that in favour
of XHTML 1.0

In the context of serving HTML documents (HTML or XHTML), then just add
your attributes as you wish and don't worry about modifying the DTD or
doctype to reflect this. HTML parsing practice (long established and
reliable) is that unknown attributes are ignored silently. In a web of
broken standards and badly-behaved browsers, then this is one of the
more trustworthy aspects.

Validation is not something that is currently achievable for practical
combinations of extended DTDs and the real-world constraints of how the
web actually behaves.

Nov 6 '05 #3
Andy Dingley wrote:
HTML parsing practice (long established and
reliable) is that unknown attributes are ignored silently.
What makes you think that the invented attributes are unknown to each
and every browser, current and future?
In a web of
broken standards and badly-behaved browsers, then this is one of the
more trustworthy aspects.
It isn't. It's a long tradition in browsers to implement new tags and
attributes, usually without adequate documentation.
Validation is not something that is currently achievable for practical
combinations of extended DTDs and the real-world constraints of how the
web actually behaves.


I don't think there's anything impossible in the idea of constructing a
DTD or a Schema for a markup system that uses HTML tags and some set of
other tags and extra attributes. The only tangible benefit would
probably be some protection against typing errors.

But using invented attributes in documents that are meant to be
processed as HTML documents is certainly unsafe.
Nov 6 '05 #4
In article <Xn*****************************@193.229.0.31>,
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote:
ni*****************@gmail.com wrote:
Hi, I want to add custom attributes to my xhtml documents to use with
my DOM scripts.
That's not useful in WWW authoring.


Actually, it can be. Note that the OP is himself providing the script
that uses the custom attributes.
How could you know whether some browser
somewhere recognizes the attributes as meaning something - and most probably
something completely different than you have in your mind?


The probability of something going wrong can be lowered by using names
that no standard would use. Eg. I could use hsivonen-foobar.

--
Henri Sivonen
hs******@iki.fi
http://hsivonen.iki.fi/
Mozilla Web Author FAQ: http://mozilla.org/docs/web-developer/faq.html
Nov 7 '05 #5
On Sun, 06 Nov 2005 18:41:06 +0200, "Jukka K. Korpela"
<jk******@cs.tut.fi> wrote:
Andy Dingley wrote:
HTML parsing practice (long established and
reliable) is that unknown attributes are ignored silently.
What makes you think that the invented attributes are unknown to each
and every browser, current and future?


I don't know and I don't care - that's just the sort of crazy
devil-may-care guy I am. Henri's "pseudo-namespacing" idea is a good
guarantee against this causing a problem, for "hit by a meteorite" and
"winnning the lottery" levels of "unlikely to collide".

It's most unlikely for a _browser_ to start using unknown attributes
that collide with this example. Browsers (OK, IE) do do this, but it's
generally well known when and where they do it. The case here is a
script attached to a particular page - now a second similar script might
well collide, but as the script is attached to the page, then this just
won't arise where there are two sets of scripts fighting over the same
content. The worst case i can imagine would be hosting this on something
like Tripod, where they slap their own scripting at top and tail outside
your control, but that's best dealt with by avoiding pikey hosting.

In a web of
broken standards and badly-behaved browsers, then this is one of the
more trustworthy aspects.


It isn't. It's a long tradition in browsers to implement new tags and
attributes, usually without adequate documentation.


So what ? That's not what I'm talking about, I'm talking about the
converse situation where browsers _reliably_ ignore unknown attributes.

The name collision problem is real, but unlikely - especially if you
choose the new names appropriately.

Incidentally (and I should have said this in my first post) the reason
why XML is significant is that XML namespacing is a better solution to
all this, but it's just impractical to use it on a web that's still
resolutely not processing content with XML tools.

I don't think there's anything impossible in the idea of constructing a
DTD or a Schema for a markup system that uses HTML tags and some set of
other tags and extra attributes.
This is certainly possible - but it's likely to cause more rendering
problems with browsers that then no longer render the content in a
standards-like mode because they regard the doctype as being more
suitable for tag soup.

There's also the question of needing to serve this DTD or schema to
every browser that decides it needs a copy. That's not something the web
architecture has ever really supported (for practical volumes) and it
could cause a very real server load problem if this page ever became
popular and user agents were grabbing copies of it.
But using invented attributes in documents that are meant to be
processed as HTML documents is certainly unsafe.


Unusual certainly, unnecessary in almost cases, but I wouldn't even go
so far as to say "unwise" if you're doing some interactive scripting
that can actually benefit from it.
Nov 7 '05 #6
Henri Sivonen <hs******@iki.fi> wrote:
> Hi, I want to add custom attributes to my xhtml documents to use with
> my DOM scripts.
That's not useful in WWW authoring.


Actually, it can be.


Some day/year/decade, maybe. But as you know, the Web is not ready for XHTML
in the first place.
Note that the OP is himself providing the script
that uses the custom attributes.


So what? He can write the script without them, too.
How could you know whether some browser
somewhere recognizes the attributes as meaning something - and most
probably something completely different than you have in your mind?


The probability of something going wrong can be lowered by using names
that no standard would use. Eg. I could use hsivonen-foobar.


This is not about standards, this is about the attributes that browsers
recognize. If you are using such attributes, you might just as well (well,
much better) use class="foobar".

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Nov 7 '05 #7
Andy Dingley <di*****@codesmiths.com> wrote:
> In a web of
broken standards and badly-behaved browsers, then this is one of the
more trustworthy aspects.
It isn't. It's a long tradition in browsers to implement new tags and
attributes, usually without adequate documentation.


So what ? That's not what I'm talking about, I'm talking about the
converse situation where browsers _reliably_ ignore unknown attributes.


If you are talking about browser behavior, "reliably" is an odd word.

You cannot know which attributes are unknown to browsers. Besides, the
principle of ignoring unknown attributes is just a description of actual
browser behavior in the world of tag soup HTML - it was never specified as a
requirement. So should you _rely_ on it? Besides, as I mentioned, it would
not guarantee anything. A browser might decide to know the attribute you have
now in your mind.

In the XML world, the idea is even stranger. There are are two feasible ways
of rendering an XML document: show the markup (perhaps nicely colored etc.),
or present the document according to well-defined rules, and "ignoring tags
and attributes you don't know" makes little sense then.
Incidentally (and I should have said this in my first post) the reason
why XML is significant is that XML namespacing is a better solution to
all this, but it's just impractical to use it on a web that's still
resolutely not processing content with XML tools.


Surely if you are going to play the XHTML+something game, then it would be
logical to use namespaced attribute names. The impracticality lies elsewhere.
But using invented attributes in documents that are meant to be
processed as HTML documents is certainly unsafe.


Unusual certainly, unnecessary in almost cases, but I wouldn't even go
so far as to say "unwise" if you're doing some interactive scripting
that can actually benefit from it.


Nobody has given any reason why it would be needed, i.e. why the same effects
could not be achieved by using normal HTML attributes. It's unwise to take a
risk (even a small one) if there is nothing to be won.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Nov 7 '05 #8
On Mon, 7 Nov 2005, Jukka K. Korpela wrote:
You cannot know which attributes are unknown to browsers.
Fair comment. For that matter you can't know whether some browser or
other isn't going to assign some special meaning to /anything/ that
you code in the source, no matter how harmless it might seem - even
comments!
Besides, the principle of ignoring unknown attributes is just a
description of actual browser behavior in the world of tag soup HTML
- it was never specified as a requirement.
Well, I'd say it was established by RFC1866 section 4.2.1.

To facilitate experimentation and interoperability between
implementations of various versions of HTML, the installed base of
HTML user agents supports a superset of the HTML 2.0 language by
reducing it to HTML 2.0: markup in the form of a start-tag or end-
tag, whose generic identifier is not declared is mapped to nothing
during tokenization. Undeclared attributes are treated similarly. The
entire attribute specification of an unknown attribute (i.e., the
unknown attribute and its value, if any) should be ignored.

Browser implementers have usually followed similar guidelines (updated
according to the version of HTML they are aiming at, of course).
So should you _rely_ on it?


I wouldn't recommend that in production; but "to facilitate
experimentation" I wouldn't rule it out.

Nov 7 '05 #9

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

Similar topics

3
by: Sorrow | last post by:
Say I have the following (simplistic) schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"...
2
by: Jordan Willms | last post by:
Hi there. I am working with lom metadata and I am a little confused with how to form the following xml element: <lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2"...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
3
by: J'son | last post by:
Guys, I have created a custom class that derives from DataList so that I can add some custom client side functionality into each new item row (<td>). Heres the class in its simplest form: ...
4
by: craig.wagner | last post by:
I have a situation where I need to carry additional information in an XML Schema. What I've found to appear to work is doing something like the following: <xs:schema xmlns:xs="...
2
by: Mikus Sleiners | last post by:
I want to create xml document that looks like this: <?xml version="1.0" encoding="utf-16"?> <Draft xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
0
by: mk189 | last post by:
Hi, I am trying to create XML schema of custom markup language, enriched by XHTML. In simplified version, the XML documet could look like that: <a:alarm-manual xmlns:a="alarm-manual"...
1
by: Artie | last post by:
Hi, Is there any way to tell an XSD Schema that you want custom error codes for particular validation failures in an XML document? To show what I mean, here's an example: XSD excerpt: ...
11
by: =?Utf-8?B?TTFpUw==?= | last post by:
I’m trying to add the following attributes (xmlns:xsi and xsi:type) to a node (Grantee) like the following: <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.