PDA

View Full Version : XML Namespaces error code - not validating


ashamsuddin
03-13-2010, 08:48 PM
My file validated before I utilized namespaces. The validator says there's a problem with my namespace declaration:?


<animals xmlns:dg="dogs.com"
xmlns:ct="cats.com">


The error says, "VC: Attribute Value Type: Element 'animals' has no declaration for an attribute named 'xmlns:dg'."


Here's the entire xml file:


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

<!-- Assignment 8
Adam Shamsuddin
CIS 072 Spring '10
-->

<!DOCTYPE animals SYSTEM "animals.dtd">


<animals xmlns:dg="dogs.com"
xmlns:ct="cats.com">
<dg:animal>
<dg:name type="dog">Butch</dg:name>
<dg:breed>German Shepherd</dg:breed>
<dg:age>1</dg:age>
<dg:weight>45</dg:weight>
<dg:color>Brown</dg:color>
<dg:remarks>Good with children</dg:remarks>
</dg:animal>
<ct:animal>
<ct:name type="cat">Phoebe</ct:name>
<ct:breed>Mixed</ct:breed>
<ct:age>3</ct:age>
<ct:weight>15</ct:weight>
<ct:color>Tabby</ct:color>
<ct:remarks>Exellent mouser</ct:remarks>
</ct:animal>
<dg:animal>
<dg:name type="dog">Rex</dg:name>
<dg:breed>Mixed</dg:breed>
<dg:age>5</dg:age>
<dg:weight>20</dg:weight>
<dg:color>Brown</dg:color>
<dg:remarks>Needs lots of attention</dg:remarks>
</dg:animal>
<ct:animal>
<ct:name type="cat">Spooky</ct:name>
<ct:breed>Mixed</ct:breed>
<ct:age>.6</ct:age>
<ct:weight>10</ct:weight>
<ct:color>Black</ct:color>
<ct:remarks>Precious</ct:remarks>
</ct:animal>
<dg:animal>
<dg:name type="dog">Harry</dg:name>
<dg:breed>Chow Chow</dg:breed>
<dg:age>12</dg:age>
<dg:weight>64</dg:weight>
<dg:color>Cinnamon</dg:color>
<dg:remarks>Ann's very spoiled dog</dg:remarks>
</dg:animal>


</animals>




And here's the DTD that is supposed to validate it:


<!--
DTD for animals

Adam Shamsuddin
CIS 072 Spring '10
-->

<!ELEMENT animals (animal+)>

<!ELEMENT dg:animal (dg:name, dg:breed, dg:age, dg:weight, dg:color, dg:remarks)>
<!ELEMENT ct:animal (dg:name, ct:breed, ct:age, ct:weight, ct:color, ct:remarks)>

<!ATTLIST dg:name type (dog | cat) #REQUIRED>
<!ATTLIST ct:name type (dog | cat) #REQUIRED>

<!ELEMENT dg:name (#PCDATA)>
<!ELEMENT dg:type (#PCDATA)>
<!ELEMENT dg:breed (#PCDATA)>
<!ELEMENT dg:age (#PCDATA)>
<!ELEMENT dg:weight (#PCDATA)>
<!ELEMENT dg:color (#PCDATA)>
<!ELEMENT dg:remarks (#PCDATA)>
<!ELEMENT ct:name (#PCDATA)>
<!ELEMENT ct:type (#PCDATA)>
<!ELEMENT ct:breed (#PCDATA)>
<!ELEMENT ct:age (#PCDATA)>
<!ELEMENT ct:weight (#PCDATA)>
<!ELEMENT ct:color (#PCDATA)>
<!ELEMENT ct:remarks (#PCDATA)>

Dormilich
03-13-2010, 09:31 PM
you have to declare the namespace definitions as well. (they are attributes)