No me valida el XML en la DTD: element is not allowed for content model

publicado por: Anonymous

Me dice que el contenido de bank está bien formado pero no validado:

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

Yo sé que la DTD está interpretada por mí y podría estar mal, pero en el XML la info está bien.

<?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>

solución

Lo que puede estar mal es el DTD justamente que puede haber más(+) de una instanciación de account, customer y 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>
   ] >
Respondido por: Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *