<?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>Technócil &#187; xml</title>
	<atom:link href="http://technocil.com/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://technocil.com</link>
	<description></description>
	<lastBuildDate>Tue, 24 Aug 2010 21:24:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dica Rapida: Pegando Twittadas com PHP</title>
		<link>http://technocil.com/2009/04/24/dica-rapida-pegando-twittadas-com-php-2/</link>
		<comments>http://technocil.com/2009/04/24/dica-rapida-pegando-twittadas-com-php-2/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 14:25:42 +0000</pubDate>
		<dc:creator>João Vagner</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Geral]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://technocil.com/2009/04/24/dica-rapida-pegando-twittadas-com-php-2/</guid>
		<description><![CDATA[Ola a todos,
Vou começar uma série de posts rapidos com dicas legais e uteis pro dia-a-dia relacionadadas a PHP.
Quase todos usam Twitter, e ja sabemos o o Twitter tem uma API para integração, porem nao e necessario usar uma API para algo basico, como pegar os Ultimos posts de alguem via RSS. Ja que RSS [...]]]></description>
			<content:encoded><![CDATA[<p>Ola a todos,</p>
<p>Vou começar uma série de posts rapidos com dicas legais e uteis pro dia-a-dia relacionadadas a PHP.</p>
<p>Quase todos usam Twitter, e ja sabemos o o Twitter tem uma API para integração, porem nao e necessario usar uma API para algo basico, como pegar os Ultimos posts de alguem via RSS. Ja que RSS e um formato XML.</p>
<p>Abaixo um codigo simples e rapido:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://twitter.com/statuses/user_timeline/14627317.rss'</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$abre</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> 
<span style="color: #000088;">$limite</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$abre</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$itens</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">utf8_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$itens</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$post</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;hr /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">==</span><span style="color: #000088;">$limite</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>$rss</strong><br />
Indica o caminho completo do RSS a ser lido.</p>
<p><strong>$abre</strong><br />
Utiliza simplexml_load_file para ler o xml e converter em um objeto/p</p>
<p><strong>$i</strong><br />
Define o inicio do loop para que possamos frear o loop no nosso limite de twittadas./p</p>
<p><strong>$limite=3</strong><br />
Definimos um limite de posts, no caso como nosso loop comeca em em 0, definindo 3, o limite de posts seria 4: 0,1,2,3</p>
<p><strong>foreach ($abre&#8211;>channel->item as $itens ) {</strong><br />
Aqui criamos um loop do item do XML e o chamamos de $itens para melhor identificação dentro do loop.  Aqui ele herda os itens de channel->item, como title, e outros</p>
<p><strong>$post = utf8_decode($itens->title);</strong><br />
Aqui usamos o UTF-8 para decodificar as mensagens evitando erros de charset e podemos interpretar para o ISO. </p>
<p><strong>echo $post .&#8217; < hr / >&#8216;;</strong><br />
Aqui imprimos o Post na tela e adicionamos a tag<br />
<hr /> para separar os posts, criando uma linha de separação.</p>
<p><strong>if($i==$limite) { break; }</strong><br />
Aqui verificamos se o nosso loop chegou ao nosso limite definido acima, se chegar coloca um fim no loop do channel->item</p>
<p>Por fim e isso, basta usar em seus blogs, e onde mais desejar ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2009/04/24/dica-rapida-pegando-twittadas-com-php-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leitura de XML &#8211; Parte 2 SimpleXML</title>
		<link>http://technocil.com/2008/12/24/leitura-de-xml-parte-2-simplexml/</link>
		<comments>http://technocil.com/2008/12/24/leitura-de-xml-parte-2-simplexml/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 13:00:14 +0000</pubDate>
		<dc:creator>João Vagner</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Destaques]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://technocil.com/2008/12/24/leitura-de-xml-parte-2-simplexml/</guid>
		<description><![CDATA[Olá Pessoal,
Primeiramente, post de dia 24 de Dezembro, desejos a todos um Feliz Natal, que estejam todos ai junto a amigos e familiares curtindo uma data especial.
Bom, demorei um pouco, mas chegou, a segunta parte de Leitura de XML usando SimpleXML, dessa vez vou usar alguns modelos, ao invez de trabalhar com o nosso Feed [...]]]></description>
			<content:encoded><![CDATA[<p>Olá Pessoal,</p>
<p>Primeiramente, post de dia 24 de Dezembro, desejos a todos um Feliz Natal, que estejam todos ai junto a amigos e familiares curtindo uma data especial.</p>
<p>Bom, demorei um pouco, mas chegou, a segunta parte de Leitura de XML usando SimpleXML, dessa vez vou usar alguns modelos, ao invez de trabalhar com o nosso Feed de RSS, vamos trabalhar com valores de cambio e pesquisa de CEP. Tudo simples e em poucas linhas.</p>
<p>Primeiramente precisamos de algum XML que seja atualizado, com os valores que temos que trabalhar. Para isso existe esse endereço: <a href="http://www.republicavirtual.com.br/cotacao/exemplos.php">http://www.republicavirtual.com.br/cotacao/exemplos.php</a></p>
<p>Não posso garantir 100% de uptime do link, pois não sei se algo vai mudar ok? Mas iremos trabalhar em cima dos retornos desse xml, ok?</p>
<h3>Simple XML</h3>
<p>O objetivo é fornecer acesso aos documentos XML usando propriedades de objetos e iterators, não é uma extensão complicada (são poucos métodos) mas é bastante flexível. </p>
<h3>Exemplo Básico</h3>
<p><strong>Importando o XML da URL: </strong><br />
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://cotacao.republicavirtual.com.br/web_cotacao.php?formato=xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p></p>
<h3>Iniciando o trabalho</h3>
<p>Aqui vamos pegar o valor do dolar comercial para compras:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// importando o arquivo</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://cotacao.republicavirtual.com.br/web_cotacao.php?formato=xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// pegando a tag dolar_commercial_compra</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dolar_comercial_compra</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As tags que podemos trabalhar podem ser encontrada nesse XML</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;webservicecotacao<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dolar_comercial_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,1260<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dolar_comercial_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dolar_comercial_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,1280<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dolar_comercial_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dolar_paralelo_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,2200<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dolar_paralelo_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dolar_paralelo_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,3000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dolar_paralelo_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;euro_dolar_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1,2410<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/euro_dolar_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;euro_dolar_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1,2410<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/euro_dolar_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;euro_real_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,6384<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/euro_real_compra<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;euro_real_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2,6408<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/euro_real_venda<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/webservicecotacao<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>
 Viram como é simples trabalhar com o SimpleXML? Agora vamos trabalhar para achar endereços de CEP ;) O XML que iremos trabalhar emcima é desse modelo:</p>
<h2>Trabalhando com CEP</h3>
<p>Código: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;iso-8859-1&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;webservicecep<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resultado<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resultado<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resultado_txt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>sucesso - cep completo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resultado_txt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uf<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SP<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/uf<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cidade<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>São Paulo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cidade<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bairro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Santana<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bairro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tipo_logradouro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Rua<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tipo_logradouro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logradouro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Duarte de Azevedo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/logradouro<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/webservicecep<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>A URL que iremos importar as consultas é: http://cep.republicavirtual.com.br/web_cep.php?cep=02036021&amp;formato=xml  </p>
<h3> Vamos ao Código:</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://cep.republicavirtual.com.br/web_cep.php?cep=02036021&amp;formato=xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;UF: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uf</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;Cidade: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cidade</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;Bairro: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bairro</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;Tipo de Logradouro: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tipo_logradouro</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;Endereço: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">logradouro</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Não recomendo que essa aplicação rode atravez da url de pesquisa, a base de dados pode ser baixada nesse endereço: <a href="http://www.republicavirtual.com.br/cep/download/cep.sql.bz2">Download</a></p>
<p>É isso, viram como é simples integrar uma pesquisa de CEP pra completar formulários de cadastros e tudo mais? Agora é com vocês ;) </p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2008/12/24/leitura-de-xml-parte-2-simplexml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Leitura de XML &#8211; Parte 1 DOM XML</title>
		<link>http://technocil.com/2008/12/09/leitura-de-xml-parte-1-dom-xml/</link>
		<comments>http://technocil.com/2008/12/09/leitura-de-xml-parte-1-dom-xml/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 15:49:46 +0000</pubDate>
		<dc:creator>João Vagner</dc:creator>
				<category><![CDATA[Desenvolvimento web]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://technocil.com/2008/12/09/leitura-de-xml-parte-1-dom-xml/</guid>
		<description><![CDATA[J&#225; precisaram ler algum XML, de algum lugar, trabalhar com esses valores? Se ainda n&#227;o precisaram, podem ter a absoluta convic&#231;&#227;o que esse dia chegar&#225;. 
Alguns aplicativos ja usam o XML como transmiss&#227;o de informa&#231;&#245;es, ou recep&#231;&#227;o de informa&#231;&#245;es. Importar ou exportar um arquivo XML &#233; simples, f&#225;cil e r&#225;pido, basta manter um padr&#227;o para [...]]]></description>
			<content:encoded><![CDATA[<p>J&#225; precisaram ler algum XML, de algum lugar, trabalhar com esses valores? Se ainda n&#227;o precisaram, podem ter a absoluta convic&#231;&#227;o que esse dia chegar&#225;. </p>
<p>Alguns aplicativos ja usam o XML como transmiss&#227;o de informa&#231;&#245;es, ou recep&#231;&#227;o de informa&#231;&#245;es. Importar ou exportar um arquivo XML &#233; simples, f&#225;cil e r&#225;pido, basta manter um padr&#227;o para ler dentro de suas tags ou escrever dentro das mesmas.</p>
<p>Alguns sistemas, blogs, entre outros dispostivos, ja est&#227;o trabalhando totalmente ou parcialmente com XML, cada um usando formata&#231;&#245;es diferentes, por&#233;m a estrutura do arquivo sempre o mesmo com a marca&#231;&#227;o de tags, exemplo de um XML comum de RSS do nosso proprio blog TECHNÓCIL:</p>
<p><strong>Nosso XML:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rss</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">xmlns:content</span>=<span style="color: #ff0000;">&quot;http://purl.org/rss/1.0/modules/content/&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">xmlns:wfw</span>=<span style="color: #ff0000;">&quot;http://wellformedweb.org/CommentAPI/&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">xmlns:dc</span>=<span style="color: #ff0000;">&quot;http://purl.org/dc/elements/1.1/&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">xmlns:atom</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2005/Atom&quot;</span> </span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">&gt;</span></span> 
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>technocil.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;atom:link</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://technocil.com/feed/&quot;</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;self&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/rss+xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://technocil.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tue, 09 Dec 2008 14:30:28 +0000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://wordpress.org/?v=2.6.5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/generator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;language<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>en<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/language<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Primeiro post, Apresentação<span style="color: #ddbb00;">&amp;#8230;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://technocil.com/2008/12/09/primeiro-post-apresentacao/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comments<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://technocil.com/2008/12/09/primeiro-post-apresentacao/#comments<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comments<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tue, 09 Dec 2008 14:29:10 +0000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pubDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dc:creator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tobias<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dc:creator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Geral]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Apresentacao]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[Technócil]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;guid</span> <span style="color: #000066;">isPermaLink</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>http://technocil.com/?p=121<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[nossa descrição do post [...]]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content:encoded<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[&lt;p&gt;Todo Conteudo do post&lt;/p&gt; </span>
&nbsp;
<span style="color: #339933;">&lt;p&gt;Segundo paragrafo&lt;/p&gt;]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content:encoded<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wfw:commentRss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://technocil.com/2008/12/09/primeiro-post-apresentacao/feed/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wfw:commentRss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Um tanto quanto grande nosso XML n&#233;? Por&#233;m ele &#233; &#243;timo para o exemplo devido aos niveis de title, e description, que ir&#225; nos exemplos abaixo. </p>
<p>Agora imaginem como ler ou obter os dados desse nosso RSS (XML). Para isso existem v&#225;rias maneiras, algumas s&#227;o usando algumas fun&#231;&#245;es do PHP como a <a href="http://br2.php.net/manual/pt_BR/function.file-get-contents.php" target="_blank">file_get_contents</a>. Exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #000088;">$conteudo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://technocil.com/feed/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$conteudo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Dependendo do seu navegador, o que ser&#225; impresso &#233; RSS(XML) do nosso blog, ou abrindo o c&#243;digo fonte do que for impresso, ver&#225; todo o XML impresso. No meu caso que uso o <a href="http://www.opera.com" target="_blank">Opera</a>, precisarei abrir o c&#243;digo fonte para ver o XML Impresso l&#225;. Agora depois trabalhar com esses dados podem ser por express&#227;o regular, e por ai vai, &#233; um trabalh&#227;o dessa maneira. O XML n&#227;o &#233; dinamico, n&#227;o pode ser interpretado pelo servidor, pode somente ser lido. Para escrever um XML com valores dinamicos sim, se usa usa PHP, e definindo no header o tipo de documento XML, por&#233;m ainda n&#227;o chegamos ao ponto de escrever nenhum XML. </p>
<p><em>Ent&#227;o para fugir do trabalho duro e chato qual a maneira mais f&#225;cil e r&#225;pida de trabalhar com XML e seus valores? </em></p>
<p>S&#227;o as mais conhecidas duas, usando uma extens&#227;o do php chamada <a href="http://www.php.net/dom" target="_blank">DOM XML</a>, que foi revisada no PHP 4.3.0 para trabalhar corretamente com o Padr&#227;o <a href="http://br2.php.net/manual/pt_BR/book.domxml.php" target="_blank">DOM</a>, e segunda op&#231;&#227;o &#233; a <a href="http://www.php.net/simplexml" target="_blank">SimpleXML</a>. </p>
<p>Instala&#231;&#227;o do <strong>DOM XML </p>
<p></strong>A instala&#231;&#227;o &#233; simples, basta<strong> descomentar </strong>a linha do php.ini que possui a extens&#227;o domxml.dll ou .so:</p>
<blockquote>
<p>extension=php_domxml.dll</p>
</blockquote>
<p>No meu caso, como uso o XAMPP 1.6.7, eu comentei a linha, pois a mesma apresentava um erro ao tentar utilizar, e eu apenas comentei e ela voltou a funcionar, no site do PHP Consta alguns avisos de vers&#245;es, dependendo da sua vers&#227;o do php, elas s&#227;o v&#225;lidas ou n&#227;o:</p>
<blockquote>
<p><strong>Nota:</strong> Esta extens&#227;o foi movida para o reposit&#243;rio <a href="http://pecl.php.net/" target="_blank">&#187; PECL</a> e n&#227;o &#233; mais distribuida em conjunto com o PHP a partir do PHP 5.0.0. </p>
<p><strong>Nota:</strong> Esta extens&#227;o n&#227;o est&#225; mais marcada como experimental. Ele ser&#225;, contudo, nunca liberada com PHP 5, e ir&#225; somente ser distribuida com PHP 4. Se voc&#234; precisa de suporte a DOM XML com PHP 5, voc&#234; pode usar a extens&#227;o <a href="http://br2.php.net/manual/pt_BR/book.dom.php" target="_blank">DOM</a>. Esta extens&#227;o domxml n&#227;o &#233; compat&#237;vel com a extens&#227;o <a href="http://br2.php.net/manual/pt_BR/book.dom.php" target="_blank">DOM</a>.</p>
</blockquote>
<p>Alguns servidores web, por&#233;m tem dificuldade em trabalhar com essa biblioteca, um exemplo &#233; a Locaweb (n&#227;o vo divulgar o nome do cliente), que sofreu para que pudessem colocar esse componente t&#227;o simples no servidor. Mas isso vai de cliente a cliente. Eu aproveitando o gancho vou divulgar a <a href="http://www.iw2servers.com.br" target="_blank">IW&#178;</a> onde possui SVN (controle de vers&#227;o), SSH e bibliotecas desses e outros usos liberadas, que hospeda aqui o TECHNOCIL.</p>
<p>Vamos aos c&#243;digos do DOM XML:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//aqui iniciamos o trabalho com o DOM, definindo o cabeçalho como versão do XML 1.0, e trabalhando com o charset em UTF-8;</span>
<span style="color: #000088;">$doc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1.0?'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8?'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// aqui fazemos o load de todo o conteúdo do XML </span>
<span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://technocil.com/feed/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Primeira fase completa, ja pegamos todo o conteudo do XML, ja iniciamos a extens&#227;o do DOM, e ja podemos usar os seus componentes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//exibe o titulo : technocil.com; pegando da tag title na raiz do XML:     &lt;title&gt;technocil.com&lt;/title&gt;</span>
<span style="color: #000088;">$titulo</span>        <span style="color: #339933;">=</span>    <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$titulo</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Caso eu queira o titulo do post eu tenho que entrar dentro dos niveis do XML:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// observe o item(1); Estamos trabalhando com niveis, parecidos com array, onde temos [0], [1], ['titulo'];</span>
<span style="color: #000088;">$tituloPost</span>        <span style="color: #339933;">=</span>    <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tituloPost</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Agora vamos pegar a descri&#231;&#227;o do Post: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// observe que estamos ainda usando o item(1), ainda estamos em um segundo nivel das marcações</span>
<span style="color: #000088;">$DescricaoPost</span>        <span style="color: #339933;">=</span>    <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$DescricaoPost</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Para ler esse conteudo dinamicamente, pode se trabalhar com foreach, listando nos -&gt;item($i) um valor de listagem contando quantos posts possuem no XML. Agora &#233; s&#243; brincarem ;) </p>
<p>Na parte dois, posto um exemplo de como pegar e trabalhar com os dados de Frete dos Correios, usando o XML de resposta das consultas por URL, e na parte 3, como trabalhar com o SimpleXML, no qual eu considero mais trabalhoso e chato.</p>
<p>At&#233; mais!</p>
]]></content:encoded>
			<wfw:commentRss>http://technocil.com/2008/12/09/leitura-de-xml-parte-1-dom-xml/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
