Pregunta

Why the following code is not correct? XMLspy finds an error at element employee

<!ELEMENT personnel (contractor*,employee*,partner*)+ >
<!ELEMENT contractor (info)>
<!ELEMENT employee(info)>
<!ATTLIST info lname CDATA #REQUIRED fname CDATA #REQUIRED hiredate CDATA #REQUIRED firedate CDATA #REQUIRED>
¿Fue útil?

Solución

You need a space after employee.

The info element is also not defined.

If what you are trying to do is get the attributes on contractor and employee, then this does it:

<!ELEMENT personnel (contractor*, employee*, partner*)+ >
<!ELEMENT contractor EMPTY>
<!ELEMENT employee EMPTY>
<!ATTLIST contractor lname CDATA #REQUIRED fname CDATA #REQUIRED hiredate CDATA #REQUIRED firedate CDATA #REQUIRED>
<!ATTLIST employee lname CDATA #REQUIRED fname CDATA #REQUIRED hiredate CDATA #REQUIRED firedate CDATA #REQUIRED>

This is valid per the DTD above:

<personnel>
  <employee lname="Foo" fname="Bar" firedate="1" hiredate="2"/>
  <contractor lname="Foo" fname="Bar" firedate="1" hiredate="2"/>
</personnel>

Or you can share the attributes declaration like this:

<!ENTITY % shared "lname CDATA #REQUIRED fname CDATA #REQUIRED hiredate CDATA #REQUIRED firedate CDATA #REQUIRED">
<!ELEMENT personnel (contractor*, employee*, partner*)+ >
<!ELEMENT contractor EMPTY>
<!ELEMENT employee EMPTY>
<!ATTLIST contractor %shared;>
<!ATTLIST employee %shared;>

This way if you need to change the list of attributes, it will change for both contractor and employee.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top