Hello. I am doing an assignment. I just need someone to validate that I did it correctly. According to the book I must: "set the default namespace for the document to the XHTML namespace". I'm a bit confused as to how to do it, but I did this:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="">

I had to do it under XTML 1.0 strict DTD. It also should use the CGI script at http://wizardworks.com/cgi/cart.

Again, I'm not asking someone to do my homework for me. I just need suggestion as to what to do. Thank you. :)

Dani AI

Generated

A quick clarification that ties the posts together: the problem was the namespace on the root element. The “default namespace” in XML/XHTML is declared on the root element with an xmlns attribute so that all unprefixed elements belong to the XHTML namespace. ’s original file used the wrong namespace URI; ’s correction (placing the XHTML namespace on the html element and adding language attributes) was the right direction.

A few practical notes that often help when an assignment specifies XHTML 1.0 Strict:

  • DOCTYPE and XML namespace are different things: the DOCTYPE selects the DTD for validation, the xmlns defines which XML namespace the element names belong to. Both need to match the XHTML profile you’re using.
  • If the page is served as application/xhtml+xml the browser parses it as XML and the document must be well-formed (no stray characters before the XML prolog, all tags closed, lower-case names, etc.). If served as text/html it will be parsed with HTML rules and some XML constraints won’t apply.
  • When using a CGI script, make sure it emits the correct Content-Type header and no extra bytes before the prolog (no BOM). For broad compatibility add both xml:lang and lang on the root element so XML processors and HTML-oriented tools both see the language.

Quick checks to run:

  • Verify server headers (example):
    curl -I http://yourserver/thatpage
    # inspect the Content-Type response header
  • Validate the output with an XHTML validator.
  • If generating pages from PHP/CGI, ensure the script prints the MIME header explicitly, for example:
    <?php
    header('Content-Type: application/xhtml+xml; charset=UTF-8');
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    ?>

If the assignment explicitly requires XHTML 1.0 Strict, follow that stack; otherwise for new projects consider the simpler HTML5 approach.

Recommended Answers

All 3 Replies

Here is what you need. It has the doctype declared and also the document elements declared. IF you take all that and paste into a notepad and save the document as index.html, then try running it in a browser. You will definitely not see anything other than the title for the page which is "title for your page goes here". Adding something like <p> This is a paragraph</p> within the body tags.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

  <head>

   <title>Title for your page goes here</title>

  </head>


  <body>



  </body>

</html>

Thank you. I saw where I messed up. Sometimes you just need a fresh pair of eyes to point out errors after staring at code for hours. Thank you very much. :)

You're welcome. Please mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.