title: "XML Parsing Error: junk after document element"
body: <p>Hey everyone I'm trying to display a Google map with dynamic locations retrieve from database I was following <a href="https://developers.google.com/maps/articles/phpsqlajax_v3" rel="nofollow">developers.google.com/maps/articles on phpsqlajax_v3</a>.I created the database and the table looks like this</p>
  
  <p><strong>trnsportpublic table</strong></p>
  
  <p>transportpublicid  int 11 AUTOINCREMENT</p>
  
  <p>transportType      varchar 60</p>
  
  <p>costPerKm          decimal(7,2)</p>
  
  <p>address            varchar 800</p>
  
  <p>teleNo             int 10</p>
  
  <p>webLink            varchar 300</p>
  
  <p>description        varchar 800</p>
  
  <p>lat                double(10,6)</p>
  
  <p>lng                double(10,6)</p>
  
  <hr>
  
  <p><strong>GenerateXml.php</strong></p>
  
  <pre><code> &lt;?php
  
            require("db_connection.php");
  
  
            function parseToXML($htmlStr) 
            { 
                $xmlStr=str_replace('&lt;','&amp;lt;',$htmlStr); 
                $xmlStr=str_replace('&gt;','&amp;gt;',$xmlStr); 
                $xmlStr=str_replace('"','&amp;quot;',$xmlStr); 
                $xmlStr=str_replace("'",'&amp;#39;',$xmlStr); // line 11  
                $xmlStr=str_replace("&amp;",'&amp;amp;',$xmlStr); 
                return $xmlStr; 
            } 
  
            // Select all the rows in the markers table
            $query = "SELECT transportType,costPerKm,address,teleNo,webLink,lat,lng FROM transportpublic";
  
            $result = mysql_query($query);
            if (!$result) 
            {
              die('Invalid query: ' . mysql_error());
            }
  
            header("Content-type: text/xml");
  
            // Start XML file, echo parent node
            echo '&lt;transportpublic&gt;';
  
            // Iterate through the rows, printing XML nodes for each
            while ($row = mysql_fetch_assoc($result)){
              // ADD TO XML DOCUMENT NODE
              echo '&lt;marker ';
              echo 'transportType="' . parseToXML($row['transportType']) . '" ';
              echo 'costPerKm="' . $row['costPerKm'] . '" ';
              echo 'address="' . parseToXML($row['address']) . '" ';
              echo 'teleNo="' . $row['teleNo'] . '" ';
              echo 'webLink="' . parseToXML($row['webLink']) . '" ';
              echo 'lat="' . $row['lat'] . '" ';
              echo 'lng="' . $row['lng'] . '" ';
              echo '/&gt;';
            }
  
            // End XML file
            echo '&lt;/transportpublic&gt;';
      ?&gt;
  </code></pre>
  
  <p>When I run <strong>GenerateXml.php</strong> on browser is gives me fillowing</p>
  
  <pre><code>XML Parsing Error: junk after document element
  Location: http://localhost:8080/testserver/generateXml.php
  Line Number 11, Column 8:
  &lt;/html&gt;
  &lt;transportpublic&gt;
  &lt;marker transportType="Bus" costPerKm="1.50" address="abc" teleNo="112554476" webLink="http://www.abc.html" lat="0.000000" lng="0.000000" /&gt;
  
  &lt;marker transportType="Train" costPerKm="12.00" address="abc" teleNo="118745963" webLink="http://www.abc.html" lat="0.000000" lng="0.000000" /&gt;
  
  &lt;marker transportType="hmmmm" costPerKm="40.00" address="abc" teleNo="112541254" webLink="http://www.abc.html" lat="-33.005985" lng="-58.501824" /&gt;
  
  &lt;marker transportType="test" costPerKm="2.00" address="abc" teleNo="112541258" webLink="http://www.abc.html" lat="39.785999" lng="-75.041976" /&gt;
  
  &lt;marker transportType="test2" costPerKm="2.00" address="abc" teleNo="112541254" webLink="http://www.abc.html" lat="6.901698" lng="79.853854" /&gt;
  
  &lt;/transportpublic&gt;
  -------^ 
  </code></pre>
  
  <hr>
  
  <p>I only got to know that after the root element I shouldn't be parsing any data it'll be taken as junk but in my GenerateXml.php i don't do anything after this line </p>
  
  <pre><code>echo '&lt;/transportpublic&gt;';
  </code></pre>
  
  <hr>
  
  <p>help me please.</p>