#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171

    Validating XML documant against DTD


    Hello;

    - In the XML below why do I get these 2 errors? They don't really make sense.
    Errors in the XML document:
    The content of element type "id" must match "(int)".
    The content of element type "name" must match "(first,last,id)".
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE name[
    		<!ELEMENT name (id, first, last) >
    		<!ELEMENT id (int)>
        	        <!ELEMENT first (#PCDATA)>
    		<!ELEMENT last (#PCDATA)>
    	]>
    	
    <name>
    	<id>4</id>
            <first>Mackie</first>
    	<last>behnam</last>
    </name>
    - What would be the best way to validate an XML document against DTD. I was hoping the browsers shows the error the same it shows the bad formatted XML. I use this.
  2. #2
  3. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171
    Can anyone help with this?
    Thanks
  4. #3
  5. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    1. When you say "(int)" the validator is going to think there should be an <int> child.
    2. In DTDs the order of elements matters.
  6. #4
  7. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171
    Originally Posted by requinix
    1. When you say "(int)" the validator is going to think there should be an <int> child.
    WHAT? No! How about the validator is going to think there is going to be an id element which is a number?
    Originally Posted by requinix
    2. In DTDs the order of elements matters.
    I am following the right order aren't I?
  8. #5
  9. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Originally Posted by zxcvbnm
    WHAT? No! How about the validator is going to think there is going to be an id element which is a number?
    DTDs don't have concepts of numbers. Just raw data like #PCDATA vs. not raw data like elements.
    Yes, that does make them fairly weak.

    Originally Posted by zxcvbnm
    I am following the right order aren't I?
    Not according to the "first,last,id" in the message.
  10. #6
  11. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171
    Originally Posted by requinix
    Not according to the "first,last,id" in the message.
    I dont see that order anywhere!

    Its id, first, last! What am I missing?
  12. #7
  13. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Originally Posted by zxcvbnm
    I dont see that order anywhere!
    It's right there in the message that you posted.
    The content of element type "name" must match "(first,last,id)".
  14. #8
  15. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,131
    Rep Power
    4304
    Perhaps it would help to explain that the comma indicates an order. (Thanks for reminding me, Requinix.) In the element type declarations for HTML 4.01, it's only used for the <html> and <fieldset> elements.
    Code:
    <!ELEMENT FIELDSET - - (#PCDATA,LEGEND,(%flow;)*) -- form control group -->
    [...]
    <!ENTITY % html.content "HEAD, BODY">
    
    <!ELEMENT HTML O O (%html.content;)    -- document root element -->
    If you want to allow them to come in any order, then you can use a "|" instead of the ",". I'm not sure if there's a way to require all of them but allow them to be in any order.

    Comments on this post

    • requinix agrees
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo