title: Having trouble understanding XML DTD. Getting getting root element not well formed error when I parse
body: <p>I'm new to XML. I'm working on an assignment and I'm stuck on external DTD validation. I get an error when I parse the file that says root element is not well formed. Both files are in the same directory.</p>
  
  <p>Here is the external DTD:</p>
  
  <pre><code>   &lt;!DOCTYPE atoms [
     &lt;!ELEMENT atoms (hydrogen, carbon, oxygen, titanium, uranium)&gt;
     &lt;!ATTLIST atoms properties CDATA #REQUIRED&gt;
     &lt;!ELEMENT hydrogen (#PCDATA)&gt;
     &lt;!ELEMENT carbon (#PCDATA)&gt;
     &lt;!ELEMENT oxygen (#PCDATA)&gt;
     &lt;!ELEMENT titanium (#PCDATA)&gt;
     &lt;!ELEMENT uranium (#PCDATA)&gt; 
     &lt;!ATTLIST properties symbol CDATA #REQUIRED&gt;
     &lt;!ATTLIST properties name CDATA #REQUIRED&gt;
     &lt;!ATTLIST properties atomicNumber CDATA #REQUIRED&gt;
     &lt;!ATTLIST properties atomicWeight CDATA #REQUIRED&gt;
     ]&gt;
  </code></pre>
  
  <p>Here is my XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!--DTD is in a local directory file named atoms.dtd --&gt;
  &lt;!-- Week 3 Homework --&gt;
  &lt;!DOCTYPE atoms SYSTEM "atoms.dtd"&gt;    
    &lt;atoms&gt;
      &lt;hydrogen&gt;   
          &lt;properties symbol="H" name="Hydrogen" atomicNumber="1" atomicWeight="1.00794"/&gt;
      &lt;/hydrogen&gt;
  
      &lt;carbon&gt;   
          &lt;properties symbol="C" name="Carbon" atomicNumber="6" atomicWeight="12.011"/&gt;
      &lt;/carbon&gt;
  
      &lt;oxygen&gt;   
          &lt;properties symbol="O" name="Oxygen" atomicNumber="8" atomicWeight="15.999"/&gt;
      &lt;/oxygen&gt;
  
      &lt;titanium&gt;   
          &lt;properties symbol="Ti" name="Titanium" atomicNumber="22" atomicWeight="47.867"/&gt;
      &lt;/titanium&gt;
  
      &lt;uranium&gt;   
          &lt;properties symbol="U" name="Uranium" atomicNumber="92" atomicWeight="238.03"/&gt;
      &lt;/uranium&gt;
    &lt;/atoms&gt;
  </code></pre>
  
  <p>Edit:</p>
  
  <p>I tried it this way just now and I'm still getting errors when I parse.</p>
  
  <p>External DTD:</p>
  
  <pre><code>    &lt;!DOCTYPE atoms [ &lt;!ELEMENT atoms (atom+)&gt;  
      &lt;!ELEMENT atom (symbol, name, atomicNumber, atomicWeight)&gt;
      &lt;!ELEMENT symbol (#PCDATA)&gt;
      &lt;!ELEMENT name (#PCDATA)&gt;
      &lt;!ELEMENT atomicNumber (#PCDATA)&gt;
      &lt;!ELEMENT atomicWeight (#PCDATA)&gt; ]&gt;
  </code></pre>
  
  <p>XML:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;!--DTD is in a local directory file named atomsV2.dtd --&gt;
      &lt;!-- Week 3 Homework --&gt;
      &lt;!DOCTYPE atoms SYSTEM "atomsV2.dtd"&gt; 
          &lt;atoms&gt;
              &lt;atom&gt; 
                  &lt;symbol H /&gt;
                  &lt;name Hydrogen /&gt;
                  &lt;atomicNumber 1 /&gt;
                  &lt;atomicWeight 1.00794 /&gt;
             &lt;/atom&gt;
  
              &lt;atom&gt;   
                  &lt;symbol C /&gt;
                  &lt;name Carbon /&gt;
                  &lt;atomicNumber 6 /&gt;
                  &lt;atomicWeight 12.011 /&gt;
              &lt;/atom&gt;
  
              &lt;atom&gt;   
                  &lt;symbol O /&gt;
                  &lt;name Oxygen /&gt;
                  &lt;atomicNumber 8 /&gt;
                  &lt;atomicWeight 15.999 /&gt;
              &lt;/atom&gt;
  
              &lt;atom&gt;   
                  &lt;symbol Ti /&gt;
                  &lt;name Titanium /&gt;
                  &lt;atomicNumber 22 /&gt;
                  &lt;atomicWeight 47.867 /&gt;
              &lt;/atom&gt;
  
              &lt;atom&gt;   
                  &lt;symbol U /&gt;
                  &lt;name Uranium /&gt;
                  &lt;atomicNumber 92 /&gt;
                  &lt;atomicWeight 238.03 /&gt;
              &lt;/atom&gt;
           &lt;/atoms&gt;
  </code></pre>