Search code examples
xmlnullentitydtdnul

XML Val Error Source of issue How to proceed


I am working in a Assessment trying to learn XML But when I valisdate it I get this

19: 30  Element type "Name" must not be declared more than once.
20: 33  Element type "Company" must not be declared more than once.
21: 38  Element type "Date_Created" must not be declared more than once.
22: 33  Element type "Programmers" must not be declared more than once.
23: 29  Element type "P1" must not be declared more than once.
24: 29  Element type "P2" must not be declared more than once.
26: 37  Element type "Last_Update" must not be declared more than once.
27: 30  Element type "Link" must not be declared more than once.
29: 30  Element type "Name" must not be declared more than once.
30: 33  Element type "Company" must not be declared more than once.
31: 38  Element type "Date_Created" must not be declared more than once.
32: 37  Element type "Programmers" must not be declared more than once.
33: 29  Element type "P1" must not be declared more than once.
34: 37  Element type "Last_Update" must not be declared more than once.
35: 37  Element type "Link" must not be declared more than once.
64: 19  The content of element type "Programmers" must match "(P1+,P2+)".
67: 26  The content of element type "Accove_Address_Book" must match "null".
74: 19  The content of element type "Programmers" is incomplete, it must match "(P1+,P2+)".
79: 12  The content of element type "Link" must match "null".
80: 21  The content of element type "Accove_Notepad" must match "null".

This is My FIle

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE Widgets [
<!ENTITY comp 'Accove Pty Ltd'>
<!ELEMENT Widgets (Catagory)>
<!ELEMENT Catagory (Tool,Storage)>
    <!ELEMENT Tool (ACCOVE)>
        <!ELEMENT ACCOVE (Name+,Company+,Date_Created+,Programmers+,Last_Update+,Link+)>
            <!ELEMENT Name (#PCDATA)>
            <!ELEMENT Company (#PCDATA)>
            <!ELEMENT Date_Created (#PCDATA)>
            <!ELEMENT Programmers (P1+,P2+)>
                <!ELEMENT P1 (#PCDATA)>
                <!ELEMENT P2 (#PCDATA)>
            <!ELEMENT Last_Update (#PCDATA)>
            <!ELEMENT Link (#PCDATA)>
    <!ELEMENT Storage (Accove_Address_Book,Accove_Notepad)>
        <!ELEMENT Accove_Address_Book (#PCDATA)>
            <!ELEMENT Name (#PCDATA)>
            <!ELEMENT Company (#PCDATA)>
            <!ELEMENT Date_Created (#PCDATA)>
            <!ELEMENT Programmers (P3*)>
                <!ELEMENT P1 (#PCDATA)>
                <!ELEMENT P2 (#PCDATA)>
                <!ELEMENT P3 (#PCDATA)>
            <!ELEMENT Last_Update (#PCDATA)>
            <!ELEMENT Link (#PCDATA)>
        <!ELEMENT Accove_Notepad (#PCDATA)>
            <!ELEMENT Name (#PCDATA)>
            <!ELEMENT Company (#PCDATA)>
            <!ELEMENT Date_Created (#PCDATA)>
            <!ELEMENT Programmers (#PCDATA)>
                <!ELEMENT P1 (#PCDATA)>
            <!ELEMENT Last_Update (#PCDATA)>
            <!ELEMENT Link (First*,Second*)>
                <!ELEMENT First (#PCDATA)>
                <!ELEMENT Second (#PCDATA)>
]>

<Widgets>
<Catagory>
    <Tool>
        <ACCOVE>
            <Name>ACCOVE</Name>
            <Company>&comp;</Company>
            <Date_Created>01/07/2011</Date_Created>
            <Programmers>
                <P1>Lauren Mullican</P1>
                <P2>Anthony Ellman</P2>
            </Programmers>
            <Last_Update>06/12/2015</Last_Update>
            <Link>image/weath1.jpg</Link>
        </ACCOVE>
    </Tool>
    <Storage>
        <Accove_Address_Book>
            <Name>Accove Address Book</Name>
            <Company>&comp;</Company>
            <Date_Created>23/04/2013</Date_Created>
            <Programmers>
                <P1>Charlie Darlington,</P1>
                <P2>Nadine Pellegrin</P2>
                <P3>Tobias Paniagua</P3>
            </Programmers>
            <Last_Update>25/04/2013</Last_Update>
            <Link>N/A</Link>
        </Accove_Address_Book>
        <Accove_Notepad>
            <Name>Accove Notepad</Name>
            <Company>&comp;</Company>
            <Date_Created>05/05/2016</Date_Created>
            <Programmers>
                <P1>Anthony Ellman</P1>
            </Programmers>
            <Last_Update>05/05/2016</Last_Update>
            <Link>
                <First>image/note1.jog</First>
                <Second>image/note2.jpg</Second>
            </Link>
        </Accove_Notepad>
    </Storage>
</Catagory>
</Widgets> 

I am not sure how to Do the DTD right.? DO I nest the elements in the DTD the same as I do in the XML.? How do I get rid of the Null?

Any help would be amzing PLS or links to reading that would outline my problems.


Solution

  • DO i nest the elements in the DTD the same as i do in the XML.

    No. You don't need to nest/indent and you definitely should not declare an element more than once.

    How do i get rid of the Null?

    You get "Null" for the elements you haven't declared.

    Here's an XML instance that has the internal subset (DTD) modified to work with the XML without any changes. Not sure if that's what you need or not, but it should at least give you a better starting point.

    <!DOCTYPE Widgets [
    <!ENTITY comp 'Accove Pty Ltd'>
    <!ELEMENT Widgets (Catagory)>
    <!ELEMENT Catagory (Tool,Storage)>
    <!ELEMENT Tool (ACCOVE)>
    <!ELEMENT ACCOVE (Name+,Company+,Date_Created+,Programmers+,Last_Update+,Link+)>
    <!ELEMENT Name (#PCDATA)>
    <!ELEMENT Company (#PCDATA)>
    <!ELEMENT Date_Created (#PCDATA)>
    <!ELEMENT Programmers (P1+,P2*,P3*)>
    <!ELEMENT P1 (#PCDATA)>
    <!ELEMENT P2 (#PCDATA)>
    <!ELEMENT P3 (#PCDATA)>
    <!ELEMENT Last_Update (#PCDATA)>
    <!ELEMENT Link (#PCDATA|First|Second)*>
    <!ELEMENT Storage (Accove_Address_Book,Accove_Notepad)>
    <!ELEMENT Accove_Address_Book (Name+,Company+,Date_Created+,Programmers+,Last_Update+,Link+)>
    <!ELEMENT Accove_Notepad (Name+,Company+,Date_Created+,Programmers+,Last_Update+,Link+)>
    <!ELEMENT First (#PCDATA)>
    <!ELEMENT Second (#PCDATA)>
    ]>
    <Widgets>
        <Catagory>
            <Tool>
                <ACCOVE>
                    <Name>ACCOVE</Name>
                    <Company>&comp;</Company>
                    <Date_Created>01/07/2011</Date_Created>
                    <Programmers>
                        <P1>Lauren Mullican</P1>
                        <P2>Anthony Ellman</P2>
                    </Programmers>
                    <Last_Update>06/12/2015</Last_Update>
                    <Link>image/weath1.jpg</Link>
                </ACCOVE>
            </Tool>
            <Storage>
                <Accove_Address_Book>
                    <Name>Accove Address Book</Name>
                    <Company>&comp;</Company>
                    <Date_Created>23/04/2013</Date_Created>
                    <Programmers>
                        <P1>Charlie Darlington,</P1>
                        <P2>Nadine Pellegrin</P2>
                        <P3>Tobias Paniagua</P3>
                    </Programmers>
                    <Last_Update>25/04/2013</Last_Update>
                    <Link>N/A</Link>
                </Accove_Address_Book>
                <Accove_Notepad>
                    <Name>Accove Notepad</Name>
                    <Company>&comp;</Company>
                    <Date_Created>05/05/2016</Date_Created>
                    <Programmers>
                        <P1>Anthony Ellman</P1>
                    </Programmers>
                    <Last_Update>05/05/2016</Last_Update>
                    <Link>
                        <First>image/note1.jog</First>
                        <Second>image/note2.jpg</Second>
                    </Link>
                </Accove_Notepad>
            </Storage>
        </Catagory>
    </Widgets>