Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

PHP XML challenge

xml

  • Please log in to reply
No replies to this topic

#1 batowiise

batowiise

    CC Newcomer

  • Just Joined
  • PipPip
  • 17 posts

Posted 16 January 2012 - 08:50 AM

Hi All,

The following code outputs in XML format and its working fine;



require("xml_dbcredential.php");

// Start XML file, create parent node

$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);

// Opens a connection to a MySQL server

$connection=mysql_connect (localhost, $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}

// Set the active MySQL database

$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}


// Select all the rows in the markers table

$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each

while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name",$row['name']);
$newnode->setAttribute("type", $row['type']);
}

echo $dom->saveXML();




The output XML format:

-<markers>
<marker name="Apaapa" type="CA"/>
<marker name="Maami" type="CC"/>
<markers>

I however want to use two tables and get the following XML output but
cannot find my way out:

-<markers>
<marker name="Apaapa" type="CA"/>
<marker name="Maami" type="CC"/>
-<line colour="#000" width="2">
<point lat="5.876435" lng="-0.847364"/>
<point lat="5.855505" lng="-0.456736"/>
</line>
-<line colour="#000" width="2">
<point lat="5.800000" lng="-0.877304"/>
<point lat="5.832321" lng="-0.874600"/>
</line>
<markers>

Your help is mush appreciated.

Regards.
Isaac
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download