Does not validate the XML in the DTD: element is not allowed for content model

0

It tells me that the bank's content is well formed but not validated:

  

Error at line 26, column 8: element 'account' is not allowed for content model 'account, customer, depositor) *'

I know that the DTD is interpreted by me and could be wrong, but in the XML the info is fine.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bank [
<!ELEMENT bank (account,customer,depositor)*>
<!ELEMENT account (#PCDATA)>
  <!ATTLIST account account-number ID #REQUIRED>
  <!ATTLIST account branch-name (Downtown|Perryridge|Brighton) #REQUIRED>
  <!ATTLIST account balance NMTOKEN #REQUIRED>
<!ELEMENT customer (#PCDATA)>
  <!ATTLIST customer customer-name ID #REQUIRED>
  <!ATTLIST customer customer-street CDATA #REQUIRED>
  <!ATTLIST customer customer-city CDATA #REQUIRED>
<!ELEMENT depositor (#PCDATA)>
  <!ATTLIST depositor account-number IDREF #REQUIRED>
  <!ATTLIST depositor customer-name IDREF #REQUIRED>
] >

<bank>
<account account-number="A-101" branch-name="Downtown" balance="500"></account>
<account account-number="A-102" branch-name="Perryridge" balance="400"></account>
<account account-number="A-201" branch-name="Brighton" balance="900"></account>
<customer customer-name="Johnson" customer-street="Alma" customer-city="Palo Alto"></customer>
<customer customer-name="Hayes" customer-street="Main" customer-city="Harrison"></customer>
<depositor account-number="A-101" customer-name="Johnson"></depositor>
<depositor account-number="A-201" customer-name="Johnson"></depositor>
<depositor account-number="A-102" customer-name="Hayes"></depositor>
</bank>
    
asked by Anónimo 22.04.2017 в 16:31
source

2 answers

0
  

What may be wrong is the DTD just that there may be more (+) than an instantiation of account, customer and depositor.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bank [
<!ELEMENT bank (account+,customer+,depositor+)>
<!ELEMENT account  EMPTY>
   <!ATTLIST account account-number ID #REQUIRED>
   <!ATTLIST account branch-name (Downtown|Perryridge|Brighton) #REQUIRED>
   <!ATTLIST account balance NMTOKEN #REQUIRED>
<!ELEMENT customer  EMPTY>
   <!ATTLIST customer customer-name ID #REQUIRED>
   <!ATTLIST customer customer-street CDATA #REQUIRED>
   <!ATTLIST customer customer-city NMTOKENS #REQUIRED>
<!ELEMENT depositor  EMPTY>
   <!ATTLIST depositor account-number IDREF #REQUIRED>
   <!ATTLIST depositor customer-name IDREF #REQUIRED>
   ] >
    
answered by 25.04.2017 / 12:32
source
0

I have passed the document through several online validators and none find the error you are referring to , indicating that the XML is valid.

To move to another level of proof I've converted the XML to JSON and the result is a correct JSON :

{
    "bank": {
        "account": [
            {
                "_account-number": "A-101",
                "_branch-name": "Downtown",
                "_balance": "500"
            },
            {
                "_account-number": "A-102",
                "_branch-name": "Perryridge",
                "_balance": "400"
            },
            {
                "_account-number": "A-201",
                "_branch-name": "Brighton",
                "_balance": "900"
            }
        ],
        "customer": [
            {
                "_customer-name": "Johnson",
                "_customer-street": "Alma",
                "_customer-city": "Palo Alto"
            },
            {
                "_customer-name": "Hayes",
                "_customer-street": "Main",
                "_customer-city": "Harrison"
            }
        ],
        "depositor": [
            {
                "_account-number": "A-101",
                "_customer-name": "Johnson"
            },
            {
                "_account-number": "A-201",
                "_customer-name": "Johnson"
            },
            {
                "_account-number": "A-102",
                "_customer-name": "Hayes"
            }
        ]
    }
}
    
answered by 23.04.2017 в 20:33