views:

22

answers:

1

Hi there,

I am generating an XML stream with a DomDocument. I need the pure XML stream, so I don't want to change the sourcecode with an xsl Transformation. Nevertheless I want people to be able to 'read' the XML in their browser without right click->View Source.

So what I do is I create a DomDocument and add a processing instruction:

$css = $xml->createProcessingInstruction("xml-stylesheet", "type=\"text/css\" href=\"xml.css\"");
$xml->appendChild($css);

Then I add all my items. The resulting XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="xml.css"?>
<OBJECT>
  <OBJECTNAME>Mi Casa</OBJECTNAME>
  <OBJECTID>1</OBJECTID>
  <DATES>
    <DATE>
      <ID>5</ID>
      <STAYFROM>05.08.2010</STAYFROM>
      <STAYTO>15.08.2010</STAYTO>
    </DATE>
  </DATES>
</OBJECT>

here is the link to the original xml:

http://www.todasmisreservas.com/service/rss.php?obj=1type=res&amp;status=confirmed&amp;xsl=1

and this is my css:

OBJECT {
background-color: #555555;
width: 100%;
}

OBJECTNAME {
display: block;
margin-bottom: 30pt;
margin-left: 0;
}

OBJECTID {
color: #FF0000;
font-size: 20pt;
}

DATES {
color: #0000FF;
font-size: 20pt;
}

STAYFROM, STAYTO, ID {
display: block;
color: #aa0000;
margin-left: 20pt;
}

I can't get it to work that the cssfile affects the xml in any way. What am I doing wrong?

Thanks

Maenny

A: 

Ok for anybody with the same problem, I finally found a solution:

When streaming a XML-stream from php make sure not only to have a valid xml file, but also to send a HTTPResponse-Header like:

header("content-type: text/xml; charset=utf-8");

Then it works.

Greetz

Maenny