DTD validation

Discussion in 'XML' started by Khisrav Kamilov, Jan 15, 2011.

  1. Hey guys,

    I would kindly to ask you to do me a favor by answering and explaining
    these terms regarding validation of DTD.

    the code of dtd looks like that:

    <?xml version="1.0" encoding="UTF-8"?>
    <!ELEMENT A (B*,C*)>
    <!ELEMENT B (C+,B?)>
    <!ATTLIST B K ID #REQUIRED>
    <!ELEMENT C (#PCDATA|D|E)*>
    <!ELEMENT D (#PCDATA)>
    <!ELEMENT E EMPTY>
    <!ATTLIST C L IDREF #IMPLIED>

    are the below terms valid or not:

    1. <A><B K="A1">abc</B><C>cde<D>fgh</D></C></A>
    2. <A><B K="A1"><C>abc</C><C>fgh</C></B></A>
    3. <A><B K="A1"><C>abc</C></B><C L="A2">def</C></A>
    4. <A><C><E/><E></E></C></A>
    5. <A><C><E><E/></E></C></A>
    6. <A><B K="A1"><C><D>abc</D></C><B K="A2"><C>def</C></B></B></A>
    7. <A><B K="A1"><C><D>abc</D></C></B><B K="A2"><C>def</C></B></A>
    8. <A><C></C></A>

    I have read few times docs about DTD, but some stuff is still not
    understandlable for me.
    Any answer and explanation would be really appreciated.

    Best regards,
    Kamilov
     
    Khisrav Kamilov, Jan 15, 2011
    #1
    1. Advertising

  2. Khisrav Kamilov wrote:

    > are the below terms valid or not:


    Consider to install and use a validating XML parser or an XML editor
    with validation support, then you can check yourself.

    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jan 15, 2011
    #2
    1. Advertising

  3. Khisrav Kamilov <> writes:

    > the code of dtd looks like that:

    [...]

    I've taken your fragments and built the following document, which I've
    named test.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE test [
    <!ELEMENT test (A*)>
    <!ELEMENT A (B*,C*)>
    <!ELEMENT B (C+,B?)>
    <!ATTLIST B K ID #REQUIRED>
    <!ELEMENT C (#PCDATA|D|E)*>
    <!ELEMENT D (#PCDATA)>
    <!ELEMENT E EMPTY>
    <!ATTLIST C L IDREF #IMPLIED>
    ]>
    <test>
    <A><B K="A1">abc</B><C>cde<D>fgh</D></C></A>
    <A><B K="A2"><C>abc</C><C>fgh</C></B></A>
    <A><B K="A3"><C>abc</C></B><C L="A3">def</C></A>
    <A><C><E/><E></E></C></A>
    <A><C><E><E/></E></C></A>
    <A><B K="A5"><C><D>abc</D></C><B K="A6"><C>def</C></B></B></A>
    <A><B K="A7"><C><D>abc</D></C></B><B K="A8"><C>def</C></B></A>
    <A><C></C></A>
    </test>

    Note that I've changed the values of IDs and the IDREF to avoid trivial
    errors. <test> is something I've introduced only to avoid having to deal
    with 8 different documents. The whole DTD is given as an "internal
    subset" also to avoid another file (if ot were a real DTD, you would
    probably prefer saving it in a "real" file").

    Then I've run the document through a document validator. On my machine,
    that was:

    xlmlint --valid --noout test.xml

    xmllint is from the libxml2-utils package on my ubuntu/linux. I'm sure
    the equivalent exists with other xml parser/validators.

    The error messages have been really informative.

    -- Alain.
     
    Alain Ketterlin, Jan 15, 2011
    #3
  4. Hallo Martin and Alain,

    First of all thanks for your effort.

    @Martin: I know,it is easiest way to check via validator, but i need
    these knowledges for exam, where I have to write all by hand.

    @Alain: Thanks for your try.

    I didnt probably write clearly my problem, as i know the right answers
    of these conditions and I wanted you guys help me with explanation.
    For instance: Term 1. <A><B K="A1">abc</B><C>cde<D>fgh</D></C></A> is
    unvalid, but i dont see really an error that it is unvalid.
    I would be really thanksful if you guys could me explain.

    Best regards,
    Kamilov
     
    Khisrav Kamilov, Jan 15, 2011
    #4
  5. Khisrav Kamilov wrote:
    ..
    > For instance: Term 1.<A><B K="A1">abc</B><C>cde<D>fgh</D></C></A> is
    > unvalid, but i dont see really an error that it is unvalid.
    > I would be really thanksful if you guys could me explain.



    Well taking a validating parser and looking as its error message(s)
    should help.
    For instance when I take

    <!DOCTYPE A [
    <!ELEMENT A (B*,C*)>
    <!ELEMENT B (C+,B?)>
    <!ATTLIST B K ID #REQUIRED>
    <!ELEMENT C (#PCDATA|D|E)*>
    <!ELEMENT D (#PCDATA)>
    <!ELEMENT E EMPTY>
    <!ATTLIST C L IDREF #IMPLIED>
    ]>
    <A><B K="A1">abc</B><C>cde<D>fgh</D></C></A>

    and use jEdits XML plugin to parse it it outputs the following error
    message:
    The content of element type "B" must match "(C+,B?)".
    Your B element looks like this:
    <B K="A1">abc</B>
    so it has a plain text node with contents "abc" as its sole child, but
    no child elements although its definition says it needs to have one or
    more C elements followed by zero or one B element. So you need to put at
    least one C element in there as in e.g.

    <A><B K="A1"><C>abc</C></B><C>cde<D>fgh</D></C></A>





    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jan 15, 2011
    #5
  6. Hi Martin,

    thank you so much for your help. now i will look carefully at all DTD
    elements.

    Best regards

    On Jan 15, 5:59 pm, Martin Honnen <> wrote:
    > Khisrav Kamilov wrote:
    >
    > .
    >
    > > For instance: Term 1.<A><B K="A1">abc</B><C>cde<D>fgh</D></C></A>  is
    > > unvalid, but i dont see really an error that it is unvalid.
    > > I would be really thanksful if you guys could me explain.

    >
    > Well taking a validating parser and looking as its error message(s)
    > should help.
    > For instance when I take
    >
    > <!DOCTYPE A [
    > <!ELEMENT A (B*,C*)>
    > <!ELEMENT B (C+,B?)>
    >   <!ATTLIST B K ID #REQUIRED>
    > <!ELEMENT C (#PCDATA|D|E)*>
    > <!ELEMENT D (#PCDATA)>
    > <!ELEMENT E EMPTY>
    > <!ATTLIST C L IDREF #IMPLIED>
    > ]>
    > <A><B K="A1">abc</B><C>cde<D>fgh</D></C></A>
    >
    > and use jEdits XML plugin to parse it it outputs the following error
    > message:
    >    The content of element type "B" must match "(C+,B?)".
    > Your B element looks like this:
    >    <B K="A1">abc</B>
    > so it has a plain text node with contents "abc" as its sole child, but
    > no child elements although its definition says it needs to have one or
    > more C elements followed by zero or one B element. So you need to put at
    > least one C element in there as in e.g.
    >
    > <A><B K="A1"><C>abc</C></B><C>cde<D>fgh</D></C></A>
    >
    > --
    >
    >         Martin Honnen
    >        http://msmvps.com/blogs/martin_honnen/
     
    Khisrav Kamilov, Jan 15, 2011
    #6
  7. Khisrav Kamilov

    Peter Flynn Guest

    On 15/01/11 15:18, Khisrav Kamilov wrote:
    > Hallo Martin and Alain,
    >
    > First of all thanks for your effort.
    >
    > @Martin: I know,it is easiest way to check via validator, but i need
    > these knowledges for exam, where I have to write all by hand.


    You really, really need to be using a validating editor when you write
    these things. That way it's just a click or keypress to get it validated.

    > @Alain: Thanks for your try.
    >
    > I didnt probably write clearly my problem, as i know the right answers
    > of these conditions and I wanted you guys help me with explanation.


    It might have been better if you had simply asked for the explanations.

    > For instance: Term 1.<A><B K="A1">abc</B><C>cde<D>fgh</D></C></A> is
    > unvalid, but i dont see really an error that it is unvalid.


    If we look at that one perhaps this will help:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE A [
    <!ELEMENT A (B*,C*)>
    <!ELEMENT B (C+,B?)>
    <!ATTLIST B K ID #REQUIRED>
    <!ELEMENT C (#PCDATA|D|E)*>
    <!ELEMENT D (#PCDATA)>
    <!ELEMENT E EMPTY>
    <!ATTLIST C L IDREF #IMPLIED>
    ]>
    <A><B K="A1">abc</B><C>cde<D>fgh</D></C></A>

    I get:

    onsgmls:test.xml:11:13:E: character data is not allowed here
    onsgmls:test.xml:11:13: open elements: A B[1]
    onsgmls:test.xml:11:19:E: end tag for "B" which is not finished
    onsgmls:test.xml:11:19: open elements: A B[1]

    That means abc is not allowed as the content of element type B.
    The element is therefore considered as still being unfinished when it
    sees the end-tag </B> because the declaration says B must contain at
    least one C possibly followed by another B. Text is not permitted.

    Change the abc to read <C>abc</C> and you now have a valid document.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
     
    Peter Flynn, Jan 16, 2011
    #7
  8. Hey Peter,

    thanks a lot, i have got already one.

    Best regards

    On Jan 16, 2:13 am, Peter Flynn <> wrote:
    > On 15/01/11 15:18, Khisrav Kamilov wrote:
    >
    > > Hallo Martin and Alain,

    >
    > > First of all thanks for your effort.

    >
    > > @Martin: I know,it is easiest way to check via validator, but i need
    > > these knowledges for exam, where I have to write all by hand.

    >
    > You really, really need to be using a validating editor when you write
    > these things. That way it's just a click or keypress to get it validated.
    >
    > > @Alain: Thanks for your try.

    >
    > > I didnt probably write clearly my problem, as i know the right answers
    > > of these conditions and I wanted you guys help me with explanation.

    >
    > It might have been better if you had simply asked for the explanations.
    >
    > > For instance: Term 1.<A><B K="A1">abc</B><C>cde<D>fgh</D></C></A>  is
    > > unvalid, but i dont see really an error that it is unvalid.

    >
    > If we look at that one perhaps this will help:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <!DOCTYPE A [
    > <!ELEMENT A (B*,C*)>
    > <!ELEMENT B (C+,B?)>
    > <!ATTLIST B K ID #REQUIRED>
    > <!ELEMENT C (#PCDATA|D|E)*>
    > <!ELEMENT D (#PCDATA)>
    > <!ELEMENT E EMPTY>
    > <!ATTLIST C L IDREF #IMPLIED>
    > ]>
    > <A><B K="A1">abc</B><C>cde<D>fgh</D></C></A>
    >
    > I get:
    >
    > onsgmls:test.xml:11:13:E: character data is not allowed here
    > onsgmls:test.xml:11:13: open elements: A B[1]
    > onsgmls:test.xml:11:19:E: end tag for "B" which is not finished
    > onsgmls:test.xml:11:19: open elements: A B[1]
    >
    > That means abc is not allowed as the content of element type B.
    > The element is therefore considered as still being unfinished when it
    > sees the end-tag </B> because the declaration says B must contain at
    > least one C possibly followed by another B. Text is not permitted.
    >
    > Change the abc to read <C>abc</C> and you now have a valid document.
    >
    > ///Peter
    > --
    > XML FAQ:http://xml.silmaril.ie/
     
    Khisrav Kamilov, Jan 16, 2011
    #8
    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. Mark McKay
    Replies:
    0
    Views:
    1,121
    Mark McKay
    Sep 22, 2004
  2. Joseph Tilian
    Replies:
    0
    Views:
    362
    Joseph Tilian
    Dec 21, 2004
  3. Ronald Fischer
    Replies:
    4
    Views:
    1,772
    Ronald Fischer
    Mar 17, 2005
  4. Replies:
    1
    Views:
    312
    George Bina
    Jan 25, 2006
  5. test
    Replies:
    2
    Views:
    2,093
    Oliver Wong
    Jul 28, 2006
Loading...

Share This Page