Xmlns= Versus meta http-equiv=

Sitepoint Memebers,

W3C says

"
You can also use attributes on elements that contain text in a language that is different from the surrounding content.
Example 1: Attribute-based language declarations in an XHTML 1.0 document served as text/html.
<html xml:lang=“en” xmlns= “http://www.w3.org/1999/xhtml”>

Alternatively, you may find documents that put language information in a meta element with http-equiv set to Content-Language.
Example 2: A Content-Language declaration in a meta element.
<meta http-equiv=“Content-Language” content=“en” />

"
Reference: Internationalization Best Practices: Specifying Language in XHTML & HTML Content

Does this mean if I have
<head><meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8” /> …

in the <head>

that I can take out
<html xml:lang=“en” xmlns= “http://www.w3.org/1999/xhtml”>

and add
<meta http-equiv=“Content-Language” content=“en” />
after
<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8” />

I never liked the web address in that opening code (xmlns=), seems like it can slow down the rendering of a site or even cause problems. The web address, http://www.w3.org/1999/xhtm, leads to a document with English text for humans to read, not servers.

I looked up xmlns in google define and I coudn’t see how declaring xmlns was needed for my xhtml site.

Thanks,

Chris

xmlns does not go out to the web. XML NameSpace is what this is used for. You can actually put anything as xmlns not just a URL. And no xmlns and http-whatever stuff is completely different. They do not have a 1 to 1 relation.

XMLNS (namespace) is used to reference the schema (XSD) for your document. There can be multiple schemas in a single document, each denoted by a namespace prefix to identify each and prevent overlap. One may be a “default” namespace, which has no prefix specified…

So let’s say you have an XHTML document, but you want to have an SVG “island” in the body of your document… you would do…


<html xmlns= "http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg">
....
<body>
    <svg:svg>
        <svg:circle display="none" ... />
    </svg:svg>
</body>
</html>

The svg:circle element in the example above includes the svg namespace prefix, which references the SVG schema, and the circle element name.

None of your html in the above would require a prefix, because it’s in the default namespace.

Transio,
So does that mean I can change
<html xml:lang=“en” xmlns= “http://www.w3.org/1999/xhtml”>
to
<html xml:lang=“en” xmlns=“aardvarks”>

What if I just have
<html xml:lang=“en”>

Thanks,

Chris

Might be easier if you drop XHTML entirely and just go with HTML.
Since you are only using pretend XHTML as it is.

Logic_earth,
I wondered about that too. I really can’t drop the xhtml now because I have <br /> not </br> (or is it <br/>) and many other slight differences between html and xhtml in 100s of places in the programming of my site.

What would pure xhtml look like for
<!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” xml:lang=“en”>?

Can I change http://www.w3.org/1999/xhtml to aardvarks ?

Thanks,

Chris

No, not really. Tho it wouldn’t make a difference in the slightest as its only pretend XHTML.

The default root element and namespace for XHTML 1.0: <html xmlns=“http://www.w3.org/1999/xhtml”> You can add additional lang and xml:lang values for example: <html xmlns=“http://www.w3.org/1999/xhtml” lang=“en” xml:lang=“en”> which will cover everything between the ‘html’ start and end tag. You were probably getting confused with HTML 4.01 <html lang=“en”> which doesn’t use a namespace.

No, you cannot change it to “aardvarks” if you intend on writing proper vanilla XHTML 1.0 only.

Actually, you can use aardvarks… though the W3C wouldn’t validate that, because “aardvarks” isn’t their URI for that namespace.

However, theoretically, if you downloaded the XHTML XSD and saved it in your folder as “aardvarks” and used that URI, any schema-aware XML parser would properly pick it up and understand what it’s dealing with.

PS - A namespace isn’t parsed or followed by browsers, AFAIK… it’s simply a universal, unique idenfier for the schema you’re referencing. The actual XSD referenced by the XHTML namespace is at a different location than the URI specified in the namespace… that URI is just a reference.

I believe you’re asking were to declare the language for your doc: as an attribute for the root element (<html>) or as a info on data in your document (<meta>).

The two have distinct roles.

W3C I18N FAQ: HTTP and meta for language information

Should I declare the language of my XHTML document using a language attribute, the Content-Language HTTP header, or a meta element?

In current practice one can find XHTML documents that provide information about the language of a page in a number of different ways.

One method is to use the lang and xml:lang attributes on the html tag.

Alternatively, you may find documents that provide this information using a meta element.

Language information may also be found in the HTTP header that is sent with a document (see the last line in the following example of an HTTP header).

It is also worth noting that the meta element and the HTTP header both support a list of values: content=“de, fr, it”.

Which of these methods is the best approach?

To answer this question, a distinction needs to be drawn between (1) specifying the language used for processing content, and (2) using metadata to identify the audience for the document. It is recommended that the lang and xml:lang attributes be used for the former, and the HTTP Content-Language setting or a meta element be used, if appropriate or needed, for the latter.

To answer directly, no, you can’t take out the language declaration from the root element and put it as a meta, since it’s not the same thing expressed differently, it’s two things having two different purposes.

Best practices says you should always put lang and xml:lang for the html root element.

Everyone,
I got it, you declare the main “language of content” using using attributes in the <html> element, and if you want to specify that you page has more than one language you add to your code, after the <html> element and befor <body>, something like this

<meta http-equiv=“Content-Language” content=“de, fr, it”/>

That takes care of my original question.

Is that right, you use an html element for an xhtml docment - you wouldn’t have something like

<Xhtml xmlns=“http://www.w3.org/1999/xhtml” lang=“en” xml:lang=“en”>

Thanks for the help,

Chris

No, you don’t have a xhtml element in HTML DTDs. The only root element for HTML documents (HTML or XHTML type) is <html>. XHTML is a reformulation of HTML in XML. That meas it will preserve the root element for HTML documents: <html>.

XML on the other hand, while restricted also to having a single root element, offers the possibility to name the elements in the way you see fit. But you’ll need to provide a DTD for it, or, most likely a XSD.

HTML has its roots in SGML, while XHTML has its roots in both SGML and XML. It all revolves around ML: Markup Language.

XHTML tries to bring together the best of the SGML and XML in order to provide a solid HTML type language and structure.

Again, declaring the lang attribute has no ties with meta.

You can declare xml:lang=“en” for <html> and also declare meta content language as “en”.

These two don’t mutually exclude.

The first refers to the root element’s language content (and all the elements in a web page are children of the root element!), as declared for any other element, the second is data on your data, saying what audience you have in mind writing your page and what languages the content may have.

<html xml:lang=“en”> is used mainly by the HTML rendering processor, meta can be used by other agents reading the page, since it provides data on data. The two coexist peacefully. Even when saying the same thing.

Noonnope,

So <html xml:lang=“en”> is for declaring the xml progamming code language. I guess xml programming language can be in other spoke/written languages. (maybe not)

and

<meta http-equiv=“Content-Language” content=“de, fr, it”/>

is for telling search engines (or someone) what spoke/written in your text will be on your page?

Thanks,

Chris

Yes, the x(ht)ml markup (not programming language) can be provided in other spoken languages, aside from english.

<html xml:lang=“en”> is for declaring what to expect as language inside the root element and that it’s a XHTML document. This attribute is a technical implementation, more than anything.

Yes, meta has the job of describing, informing about the content language of your page. This tag is more of a semantic implementation, more than anything. It describes your data, it’s not part of the technical implementation process of your data.

Being just an information on data, it only helps if provided with accuracy. But if not, it will not impede with your page’s overall behavior.

While in the case of the lang attribute, this one is taken more seriously into consideration by the agents, whether it’s about the root element, or any other element for that matter. It actually triggers element specifics, it’s not about vague info.

Noonnope,
What does “inside the root element” mean? What is a root element?

Thanks,

Chris

<html> is the point where it all starts. It defines a tree structure, where it it’s the root.

The root element <html> is the main “container” for your HTML document. All the other elements are children of the root elements. That’s what “inside the root element” means.

AFAIK, the lang attribute on the html element does NOT reference the language of the markup, but the language of the text within the document.

I’ve never seen any other markup for XHTML besides English. Further research has confirmed this… XHTML is a singular specification, and its elements and attributes are always in English.

And given that HTML is an English markup language, having the lang attribute specify that it’s in English would be redundant.

so in

<html xmlns=“http://www.w3.org/1999/xhtml” lang=“en” xml:lang=“en”>

which is just about universally used, lang=“en” xml:lang=“en” declare English as the language of the text the author is using. One of them would be redundant. Ren, on another thread was telling me that if your code is xhtml don’t use lang=“en”. I follwed his advice and it removed a validation error (for mobile phone validation). If English is the only language for xhtml and so not declared (or declared with “EN” in the DTD) I don’t see how both of

lang=“en” xml:lang=“en”

is not redundant for declaring language of the text.

Thanks,

Chris

The lang and xml lang Attributes and XHTML

Thanks for the effort but I was lost with the first sentence.

He writes,

“The lang attribute is used for setting the language of a whole document or a specific part of the document.”

What does “the lang attribute” mean? lang=“en” OR xml:lang=“en” ?

Later on he writes "When to use ‘‘xml:lang’’ but never "When to use ''lang=“en”.

The whole page really is pretty vague.

Thanks,

Chris