hi sir! little bit lost here in php. Pls help!
how can I add css file for may xml created from php?

<?php
bla bla bla.....
---------<?xml-stylesheet type="text/css" href="markers.css"?>-------how can i add this line?
echo '<markers>';
while ($row = @mysql_fetch_assoc($result)){
  echo '<marker ';
  echo 'name ="' . parseToXML($row['name']) . '" ';
  echo 'address ="' . parseToXML($row['address']) . '" ';
  echo 'lat ="' . $row['lat'] . '" ';
  echo 'lng ="' . $row['lng'] . '" ';
  echo '/>';
}
echo '</markers>';
?>

Recommended Answers

All 2 Replies

I have done an example here .

In your php file

<?php

class SimpleXMLElement_Plus extends SimpleXMLElement {

    public function addMyCss( $name, $value )
    {
        $dom_sxe = dom_import_simplexml($this);       
        $dom_parent = $dom_sxe->ownerDocument;       
        $xpath = new DOMXPath($dom_parent);
        $first_element = $xpath->evaluate('/*[1]')->item(0);
        $pi = $dom_parent->createProcessingInstruction($name, $value);
        $dom_parent->insertBefore($pi, $first_element);
    }
} 


$xml = new SimpleXMLElement_Plus('<xml/>');
$xml->addMyCss('xml-stylesheet', 'type="text/css" href="markers.css"');
$track = $xml->addChild('markers');
for ($i = 1; $i <= 10; ++$i) {
    $marker = $xml->addChild('marker');
    $marker->addChild('name', "name$i");
    $marker->addChild('address', "address $i");
    $marker->addChild('lat', "lat $i");
    $marker->addChild('lng', "lng $i");
}

Header('Content-type: text/xml');
print($xml->asXML());
?>

& in your markers.css

markers
{
margin:10px;
background-color:#ccff00;
font-family:verdana,helvetica,sans-serif;
}

name
{
display:block;
font-weight:bold;
}

address, lat, lng
{
display:block;
color:#636363;
font-size:small;
font-style:italic;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.