XML DTD Validation, namespaces and best practices

Discussion in 'XML' started by johnmack@gmail.com, Nov 2, 2005.

  1. Guest

    In my XML instances I want to use the XLink namespace for attributes on
    certain elements. I'm having quite a hard time determining how to
    reflect this properly in my DTD and XML instances.

    In my instance, to declare the namespace, I have this on my root
    element:
    <root xmlns:xlink="http://www.w3.org/1999/xlink">
    ...
    <mylink xlink:href="http://foo.com">
    ....

    Declaring things as I've done on the <root> element here, is this
    proper? Do I have to declare 'xmlns:xlink' as an attribute on <root>
    in my DTD? Or do attributes starting with 'xmlns:' trigger an innate
    XML processing command and therefore do not need to be defined in a
    DTD?

    In my DTD I have explicitly defined "xlink:href" as attribute like so:
    <!ELEMENT mylink (#PCDATA)>
    <!ATTLIST mylink
    xlink:href CDATA #REQUIRED>

    Is this an acceptable approach or is the following a better way to do
    it in the DTD?:
    <!ATTLIST mylink
    xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink">


    I'm using the XML validator at:
    "http://www.stg.brown.edu/service/xmlvalid/", and when I have 'Relax
    namespace checks' selected, my XML documents validate. To clarify
    further they only validate when I have the namespace in <root> ( as
    noted above) *and* declaring explicitly 'xlink:href' as an attribute
    (<!ATTLIST mylink xlink:href CDATA #REQUIRED>) on 'mylink' in my DTD.
    Since the validator says this is OK, I'm using what I've done is OK?
    It seems weird to have to explicitly declare 'xlink:href' as an
    attribute in my DTD so I'm thinking this may not be proper. Are there
    other options for me to pursue? Is there a suggested best practice?
    It's been tough to find clear solutions for this matter.

    Thanks for any insight,

    John Mack
     
    , Nov 2, 2005
    #1
    1. Advertising

  2. In article <>,
    <> wrote:

    >In my instance, to declare the namespace, I have this on my root
    >element:
    > <root xmlns:xlink="http://www.w3.org/1999/xlink">
    > ...
    > <mylink xlink:href="http://foo.com">
    > ....
    >
    >Declaring things as I've done on the <root> element here, is this
    >proper?


    Yes. You don't have to declare them on the root, but it's often
    convenient.

    >Do I have to declare 'xmlns:xlink' as an attribute on <root>
    >in my DTD?


    Yes.

    >Or do attributes starting with 'xmlns:' trigger an innate
    >XML processing command and therefore do not need to be defined in a
    >DTD?


    No, DTDs have not been updated to take account of namespaces, so
    namespace declaration attributes have to be declared like any others.

    >In my DTD I have explicitly defined "xlink:href" as attribute like so:
    ><!ELEMENT mylink (#PCDATA)>
    ><!ATTLIST mylink
    > xlink:href CDATA #REQUIRED>
    >
    >Is this an acceptable approach or is the following a better way to do
    >it in the DTD?:
    ><!ATTLIST mylink
    > xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink">


    The second saves you having to remember to put it on the element in
    the instance, but if it's declared in the external subset you'd better
    be sure that all the XML processors you use read the external subset.

    >I'm using the XML validator at:
    >"http://www.stg.brown.edu/service/xmlvalid/", and when I have 'Relax
    >namespace checks' selected, my XML documents validate. To clarify
    >further they only validate when I have the namespace in <root> ( as
    >noted above) *and* declaring explicitly 'xlink:href' as an attribute
    >(<!ATTLIST mylink xlink:href CDATA #REQUIRED>) on 'mylink' in my DTD.
    >Since the validator says this is OK, I'm using what I've done is OK?
    >It seems weird to have to explicitly declare 'xlink:href' as an
    >attribute in my DTD so I'm thinking this may not be proper. Are there
    >other options for me to pursue? Is there a suggested best practice?


    The "relaxed namespace checks" are supported by any standard. Your
    document is not DTD-valid unless you declare the attribute. On the
    other hand, you don't *have* to make your documents DTD-valid at all.
    If you find that the "relaxed" validation is useful, and you don't
    need true DTD-validity, then it's a reasonable approach.

    -- Richard
     
    Richard Tobin, Nov 2, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Deelsnyder

    Best Practices - solution - namespaces - classes

    Craig Deelsnyder, Aug 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    436
    Vincent V
    Aug 4, 2003
  2. David  Manheim

    Namespaces and Custome DTD's

    David Manheim, Jul 13, 2005, in forum: XML
    Replies:
    1
    Views:
    355
    Richard Tobin
    Jul 18, 2005
  3. Johan Nilsson
    Replies:
    3
    Views:
    395
    Siemel Naran
    Mar 10, 2005
  4. test
    Replies:
    2
    Views:
    2,128
    Oliver Wong
    Jul 28, 2006
  5. Chicken McNuggets

    Best book on C gotchas and best practices?

    Chicken McNuggets, Jul 31, 2013, in forum: C Programming
    Replies:
    9
    Views:
    279
    Fred J. Tydeman
    Aug 5, 2013
Loading...

Share This Page