I have successfully generated an xml file using dom in php dynamically, but I am unsure how to put CSS link in it.

I need the php code to link CSS with that automatically generated XML file.

1 Answers

1
ThW On Best Solutions

To link an CSS in XML you can use the xml-stylesheet processing instruction. Use the corresponding method on DOMDocument to create it and then append/insert it just like any other node.

$document = new DOMDocument();
$document->appendChild(
  $document->createProcessingInstruction(
    'xml-stylesheet', 'type="text/css" href="styles.css"'
  )
);
$document->appendChild(
  $document->createElement('example')
);
echo $document->saveXML();

Output:

<?xml version="1.0"?> 
<?xml-stylesheet type="text/css" href="styles.css"?> 
<example/>