XML DOM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

 

I'm using PHP to output an XML file for use with Google Maps - the XML file
containing data for each location.

 

$dom = new DOMDocument("1.0");

 

$locations = $dom->createElement("locations");

$dom->appendChild($locations);  //  append $node as a child of $dom  (I
think???)

 

for($i=1;$i<=$number_of_locations;$i++) {

                $row = mysql_fetch_assoc($query);

 

                $location = $dom->createElement("location");
//  Create a new element "location"

                $locations->appendChild($location);                       //
Append "location" as a child of "locations" (the document shell)

                

                $name =
$dom->createElement("name",htmlentities($row['location_name']));

                $location->appendChild($name);

 

.. And so on

 

Ultimately, I want to have an XML output that looks like (which I'm ALMOST
getting, but.):

 

<?xml version="1.0" ?> 

<locations>

      <location>

        <name>Some company name</name> 

        <street>12345 Some Street</street> 

        <street2>Some Apt Number</street2> 

        <city>Some City</city> 

        <state>CA</state> 

        <zip>90210</zip> 

      </location>

</locations>

 

 

Then I'm using JS to feed each location into Google Maps, creating a sidebar
entry and marker for each.

 

Problem:

If street2 (or any other field) has no value, PHP is outputting the XML node
as <street2 />, which is producing a JS error when I try to call:

<script type="text/javascript">..

street2 = x[i].getElementsByTagName("street2")[0].childNodes[0].nodeValue;

                ...</script>   (Because the requested node has no
.nodeValue, I'm assuming???)

 

Question:

Can I tell PHP to output the XML node as <street2></street2> instead of
<street2 /> so that JS sees that the object has a value, but the value is ""
(blank)?

 

Many thanks in advance for any help.

 

Ben


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux