Skip to content Skip to sidebar Skip to footer

Trouble Getting Declared Namespaces To Work

I am trying to get namespaces written in an external css (two separate files actually). When I run the file on my browser it will not use the declared namespaces. I think that the

Solution 1:

In your XHTML:

  1. Your markup is not well-formed:

    • Your XML declaration should come first, then your doctype declaration:

      <?xml version="1.0" encoding="utf-8"?><!DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    • Some of your <link /> tags aren't closed properly, they should be:

      <link rel="stylesheet" href="movies.css"type="text/css" />
      <link rel="stylesheet" href="actors.css"type="text/css" />
      
  2. Your page must be served as application/xhtml+xml by the server. Typical servers don't know that you're serving XHTML, so they send them as text/html instead. Browsers won't be able to treat text/html files as XML, so they won't apply CSS to your custom XML elements.

    If you work with PHP, it's simply a matter of adding this to the very top of your XHTML file:

    <?php header('Content-Type: application/xhtml+xml'); ?>

    Or in ASP, add this:

    <% Response.ContentType = "application/xhtml+xml"; %>
    

    You should also have an accompanying meta tag, but it's not necessary for your page to validate, and browsers ignore it anyway:

    <metahttp-equiv="Content-Type"content="application/xhtml+xml; charset=utf-8" />

    You can find a short history lesson on UAs treating XHTML as HTML tag soup in this answer to better understand this.

In your CSS:

  1. It's font-weight: bold, not font-style: bold.

  2. It's font-style: italic, not font-style: italics.

  3. Make sure that your @namespace statements are placed at the beginning of your stylesheets. From the spec:

    Any @namespace rules must follow all @charset and @import rules and precede all other non-ignored at-rules and rule sets in a style sheet.


But with all that said, why aren't you placing your actors and movies into their own XML files, then transforming them using XSLT into familiar, actual XHTML?

Post a Comment for "Trouble Getting Declared Namespaces To Work"