XHTML transitional self closing tags - xhtml

I am using the
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Doctype and notice that I'm being suggested elements such as
<P /> instead of <p> </p>
In my eclipse IDE. Is this just a self closing tag? is the capital letter a standard of somesort?

Yes, <p /> is a self-closing tag for <p></p>, and is valid in XHTML (but not HTML5).
Every browser that supports XHTML supports the self-closing syntax for every tag:
Elements that are declared in the DTD as EMPTY can have an end tag or can use empty element shorthand (see Empty Elements).
Having said that, a self-closing paragraph makes no sense.
It's important to note that XHTML elements must be written in lower-case:
XHTML documents must use lower case for all HTML element and attribute names. This difference is necessary because XML is case-sensitive e.g. <li> and <LI> are different tags.
It's also important to note that the XHTML doctype is outdated as of 2012. I strongly suggest switching to HTML 5 instead.
Hope this helps! :)

Related

XHTML namespaces and CSS attribute selectors

I can't figure out how to get CSS attribute selectors to style elements based on namespaced attributes without resorting to the ordinary HTML name of the namespaced attribute (including the colon).
Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:foo="https://stackoverflow.com/foo">
<head>
<title>CSS Attribute Selectors with namespaces</title>
<style>
#namespace foo "http://www.stackoverflow.com/foo";
span[foo|id=bar] { font-family: monospace; font-weight: bold; }
</style>
</head>
<body>
<span foo:id="bar">Should be monospace bold</span>
</body>
</html>
Test case:
I opened the file in both Chrome and Firefox by typing the appropriate file:/// URL into my address bar; in neither case does it show up correctly. It also does not show up correctly on Stack Overflow.
If I change the snippet to include the HTML attribute name:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:foo="https://stackoverflow.com/foo">
<head>
<title>CSS Attribute Selectors with namespaces</title>
<style>
#namespace foo "http://www.stackoverflow.com/foo";
span[foo\:id=bar] { font-family: monospace; font-weight: bold; }
</style>
</head>
<body>
<span foo:id="bar">Should be monospace bold</span>
</body>
</html>
... it works correctly (both using my local browser and on the Stack Overflow snippet).
I've read the set of gotchas included in Can you style XHTML elements in another namespace using id and class name css selectors? and Do CSS namespace attribute selectors work with XHTML/HTML elements? but I have not yet been able to figure this out; I believe I've done everything both questions' answers suggest.
Removing the DOCTYPE didn't do it, although I suspect some kind of DOCTYPE problem given that the HTML form works and the XHTML form does not.
I must be missing something simple!
Your document needs to be processed as an XHTML document for the XML namespaces to work. Note that having an XHTML DOCTYPE and the relevant xmlns attributes is not enough.
You do this on the server side by serving the document as Content-Type: application/xhtml+xml, or on the file system by saving the document with a .xhtml file extension instead of .html. For a very quick and dirty test case you can even copy your entire markup, drop it in the address bar, prepend data:application/xhtml+xml,, and navigate to the resulting data URI.
This is mentioned in very brief passing by the first question you link to:
If I switched the mime-type to application/xhtml+xml
Note also that the namespace in your CSS must exactly match the namespace in the markup. #namespace foo "http://www.stackoverflow.com/foo"; does not match xmlns:foo="http://stackoverflow.com/foo" because of the www.. (Interestingly, the foo identifiers do not need to match, because unlike the namespaces themselves the identifiers are separate.)

What is minimal XHTML? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a question, basically I need to write the code for a table with minimal XHTML and CSS. I'm not quite sure what minimal XHTML is but my guess is that it's just showing the initial XML code without the doc type etc. That's what a site says.
But then all the examples of minimal XHTML contain the strict, transitional and frameset document types which is confusing me because wouldn't that just make it a normal XML page then?
Minimal XHTML is what is at least required as w3c recomendations, to be included in such type of document.
You can find details here w3c
I quote the most relevant of it...
The root element of the document must be html.
The root element of the document must contain an xmlns declaration for the XHTML namespace [XMLNS]. The namespace for XHTML is defined to
be http://www.w3.org/1999/xhtml. An example root element might look
like:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
There must be a DOCTYPE declaration in the document prior to the root element. The public identifier included in the DOCTYPE
declaration must reference one of the three DTDs found in DTDs using
the respective Formal Public Identifier. The system identifier may be
changed to reflect local system conventions.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
The DTD subset must not be used to override any parameter entities in the DTD.
The question being: "(a)Illustrate using minimal XHTML and CSS how you would layout a data table like the following..." then it shows a table.
As a teacher—and if that's all you have to go on—I would read that as: "Show the basic HTML and CSS needed to construct this table, without adding unnecessary details." Presumably the examiner doesn't want to trawl through a lot of fancy code that shows off your skills but that isn't really needed to demonstrate you know how to code a table appropriately.
In principle, the most logical interpretation of “minimal” is “using the smallest amount of characters”. Probably line breaks are not counted, however; omitting them would make the code essentially less convenient to read. The problem still isn’t well-defined, since it does not define what XHTML version(s) may be used.
If XHTML linearization (syntax) for HTML5, known as XHTML5, is allowed, then the minimal XHTML document containing a table and reference to a style sheet is the following (when line breaks are not counted:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title>
<link rel="stylesheet" href="a.css"/></head>
<body>
<table><tr><td></td></tr></table>
</body>
</html>
Techically the style sheet URL could be shorter, but it’s not reasonable to use a URL that does not end with .css.
Other XTHML versions have different rules, resulting in a somewhat longer minimal document, due to the length of the doctype declaration.

IE8 displaying page incorrectly

For one reason or the other IE8 is not displaying my webpage properly. It works on every other major browser but everything is helter-skelter when I try to open the page on IE8 and since majority of the users of this page primarily use IE8, I cannot ignore it. Here's the link to it: http://www.gradschool.purdue.edu/gradexpo/mailinglist/
You haven't set a doctype. Put this at the very top of your page:
<!DOCTYPE html>
IE put itself into 'quirks' or Compatibility mode when it doesn't see a doctype, which will mess up your layout. Specifying a doctype will kick it into Standards mode which will remedy most problems. IE is still pretty useless at rendering CSS properly, so you might still have some issues.
Note you could also use the HTML 4.01 Strict doctype, but this will give the same result:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
get a doctype at the top of your html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
then run it through http://validator.w3.org
and fix other errors
In addition to the critical error of a missing doctype as others have pointed out, you have a few serious HTML errors.
W3C Validation
You have repeated your closing tags for </body> and </html>. You also have a couple unused closing div tags, </div>. All of the meta tags in your <body> need to be moved to within the <head> section. Browsers will handle these kinds of errors with unpredictable rendering.

Nested CSS Problem

I have the following code:
<table class="top">
<tr>
<td>
<table class="errMsg"><tr><td>Required field must not be blank </td></tr></table>
<td/>
<tr/>
</table>
I am trying to style to the error message but the "top" style keeps applying:
.top td {
color:black;
}
.errmsg td {
color:red;
}
The error message comes out black...how can I fix this?
Not sure if this matters but when I take out the dtd it works fine but it messes up the positioning.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Class names are case sensitive, so errmsg is not the same as errMsg. Change <table class="errMsg"> to <table class="errmsg">.
I would use either a strict or transitional doctype. The xhtml doctype isn't well supported and my understanding is that it's basically going away.
for strict use:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
for transitional use:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
I almost always use strict as it offers the best browser support. Typically there are only a couple minor styles I need to set to fix some margins on certain tags.
Also, it's worth noting that when you completely remove the doctype line all browsers fall back to quirks mode, which is rarely a good thing. W3.org has a list of valid doctypes you might want to investigate.

Full Example XHTML document showing how to define additional attributes

I am trying to extend an xhtml document to allow extra attributes.
In the w3.org it gives an example like so:
<!ATTLIST a
myattr CDATA #IMPLIED
>
See: 6.1. Defining additional attributes -
http://www.w3.org/TR/1999/xhtml-modularization-19990406/developing.html#s_dev_attrs
However i am not sure where to put that statement.
I have tried adding it like so:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<!ATTLIST a
myattr CDATA #IMPLIED
>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
</head>
<body>
...
</body>
But when I pick up the doc using DOM that extra DTD statement is ignored.
I have also tried:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ATTLIST a
myattr CDATA #IMPLIED
>
]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
</head>
<body>
...
</body>
But that really caused DOM to throw a wobbly.
So I'd appreciate it if someone could show me a sample xhtml document that has an additional attribute defined. (i.e minimal full doc that could validate)
As you might have guessed....xhtml is not my strong point.
Your second example is correct, apart from the missing </html> end-tag. With that added it parses OK for me. What exactly “throws a wobbly”?
The ATTLIST declaration must indeed go in the DTD, the internal subset of which is within square brackets inside the DOCTYPE declaration.
(What are you hoping to achieve with this? Browsers don't care, even if they are running in native application/xhtml+xml mode. In normal text/html tag soup mode the DTD internal subset will just confuse them.)

Resources