<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Peter Törnstrand &#187; processing instruction</title>
	<atom:link href="http://www.tornstrand.com/tag/processing-instruction/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tornstrand.com</link>
	<description>Drupal, PHP and web developing</description>
	<lastBuildDate>Fri, 16 Apr 2010 07:04:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Reading a XML processing instruction with PHP</title>
		<link>http://www.tornstrand.com/2008/10/21/reading-a-xml-processing-instruction-with-php/</link>
		<comments>http://www.tornstrand.com/2008/10/21/reading-a-xml-processing-instruction-with-php/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 15:56:36 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[processing instruction]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xpath]]></category>
		<category><![CDATA[xsl]]></category>

		<guid isPermaLink="false">http://www.tornstrand.com/2008/10/21/reading-a-xml-processing-instruction-with-php/</guid>
		<description><![CDATA[I&#8217;m doing some XSL transformations in a project I&#8217;m involved in right now. The XML documents that are beeing transformed all include a xml-stylesheet processing instruction that I need to read in order to know what stylesheet to use for a specfic document. To my surprise, reading processing instructions from a DOMDocument in PHP was [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m doing some XSL transformations in a project I&#8217;m involved in right now. The XML documents that are beeing transformed all include a xml-stylesheet processing instruction that I need to read in order to know what stylesheet to use for a specfic document. To my surprise, reading processing instructions from a DOMDocument in PHP was not so easy as one might assume.</p>
<p><span id="more-29"></span>I wont go into details and tell you about all the hair (of which I have very little) I lost during my search for a way to get ahold of those processing instructions. In the end I used a XPath expression to select the PI. Below you&#8217;ll find the code I used.</p>
<p><code>$doc = new DOMDocument;<br />
$doc-&gt;load("document.xml");<br />
$xpath = new DOMXpath($doc);<br />
$nodes = $xpath-&gt;evaluate("/child::processing-instruction('xml-stylesheet')");<br />
if(!empty($nodes))<br />
$pi = $nodes-&gt;item(0);<br />
print $pi-&gt;target;<br />
print $pi-&gt;data;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tornstrand.com/2008/10/21/reading-a-xml-processing-instruction-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
