Namespaces

B

Bill Cunningham

I always begin my xml pages as
<?xml version="1.0"?> but I've seen different versions called namespaces
added like this
<xmlns="www.w3.org/1999/xhtml"> or somethnig to that effect the syntax isn't
right. What does xmlns: do?

Bill
 
M

Martin Honnen

Bill said:
I always begin my xml pages as
<?xml version="1.0"?> but I've seen different versions called namespaces
added like this
<xmlns="www.w3.org/1999/xhtml"> or somethnig to that effect the syntax isn't
right. What does xmlns: do?

I am sure there should be no xmlns in the XML declaration so an XML file
can start with
<?xml version="1.0"?>
or with
<?xml version="1.0" encoding="UTF-8"?>

As for xmlns, it is an attribute you can set on any element to declare
its namespace e.g.
<html xmlns="http://www.w3.org/1999/xhtml">
makes the <html> element to be in the XHTML namespace.

Namespaces are a way to group and identify the elements used in your
markup, see
http://www.w3.org/TR/REC-xml-names/
 
B

Bill Cunningham

As for xmlns, it is an attribute you can set on any element to declare
its namespace e.g.
<html xmlns="http://www.w3.org/1999/xhtml">
makes the <html> element to be in the XHTML namespace.

Namespaces are a way to group and identify the elements used in your
markup, see
http://www.w3.org/TR/REC-xml-names/
Okay. I think XHTML may take over HTML myself but if I wanted to write an
XHTML page do I need this
<?xml version="1.0"?>
Or would the begining tage be
<html xmlns="www.w3.org/1999/xhtml"> ?

Bill
 
A

Ashmodai

Bill said:
Okay. I think XHTML may take over HTML myself but if I wanted to write an
XHTML page do I need this
<?xml version="1.0"?>
Or would the begining tage be
<html xmlns="www.w3.org/1999/xhtml"> ?

Bill

<?xml version="1.0" encoding="your-encoding-here"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML MyXHTMLVersion//EN"
"URI-of-that-DTD">
<html xmlns="http://www.w3.org/1999/xhtml">

would be the correct beginning of an XHTML file.
The correct beginning of an HTML file would be

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML MyHTMLVersion//EN"
"URI-of-that-DTD">
<html>

The Doctypes can be found at http://www.w3.org and via most search
engines ("HTML Doctype DTD" should turn up some results).

The XML Processing instruction (PI) may be dropped when using XHTML, but
it is mandatory for standards compliant XML. The Doctype header is
mandatory for valid (X)HTML (no validity without a DTD) and the XML
Namespace is mandatory for validity in XHTML as the DTD specifies it as
a mandatory attribute. Also note that all URIs have to be written
exactly the same way they are written in the standards.
"http://www.w3.org/1999/xhtml", "http://w3.org/1999/xhtml",
"www.w3.org/1999/xhtml", "HTTP://W3.ORG/1999/xhtml" and
"//w3.org/1999/xhtml" are all different namespaces and only the first
one is the correct namespace for XHTML.

Also note that the DTDs need to be complete (i.e. both the PUBLIC
identifier (that string with the -//W3C// etc) and the SYSTEM identifier
(the URI of the DTD) need to be specified).

Don't understand? Read a tutorial. Search engines might help.

-ap
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top