0

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>';
?>
2
Contributors
2
Replies
29
Views
3 Years
Discussion Span
Last Post by Bachu
0

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;
}

Edited by Bachu: text correction

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.