I'm trying to update a XML with PHP, and i'm sucessful, but there is a little problem: I don't know how to get XML "class" and edit via PHP. This example was very helpful, here is my form:
<form name="form1" action="converte.php" method="post">
<input type="text" name="referencia" id="referencia" placeholder="Insira a referência">
<input type="text" name="titulo" id="titulo" placeholder="Escreva o título">
<input type="text" name="descricao" id="descricao" placeholder="Insira a descrição">
<input type="text" name="cidade" id="cidade" placeholder="Insira a cidade">
<input type="text" name="bairro" id="bairro" placeholder="Bairro">
<input type="text" name="imagem" id="imagem" placeholder="LINK DA IMAGEM (.jpg)">
<input type="text" name="banheiros" id="banheiros" placeholder="Banheiros">
<input type="text" name="quartos" id="quartos" placeholder="Quartos">
<input type="text" name="preco" id="preco" placeholder="R$ 0.000.000">
<input type="text" name="tipo" id="tipo" placeholder="Tipo do imóvel (apartamento, casa, comercial....)">
<input type="text" name="direcionamento" id="direcionamento" placeholder="Link do imóvel no site, para direcionar o clique">
<input type="submit" value="Gerar XML">
</form>
Here is my PHP (converte.php):
<?php
$postReferencia = $_POST['referencia'];
$postName = $_POST['titulo'];
$postDescricao = $_POST['descricao'];
$postCidade = $_POST['cidade'];
$postBairro = $_POST['bairro'];
$postImagem = $_POST['imagem'];
$postBanheiros = $_POST['banheiros'];
$postQuartos = $_POST['quartos'];
$postPreco = $_POST['preco'];
$postTipo = $_POST['tipo'];
$postDirecionamento = $_POST['direcionamento'];
// load the document
// the root node is <info/> so we load it into $info
$info = simplexml_load_file('facebook.xml');
// update
$info->listing->home_listing_id = $postReferencia;
$info->listing->content_ids = $postReferencia;
$info->listing->name = $postName;
$info->listing->description = $postDescricao;
$info->listing->address->component = $postCidade;
$info->listing->neighborhood = $postBairro;
$info->listing->image->url = $postImagem;
$info->listing->num_baths = $postBanheiros;
$info->listing->num_beds = $postQuartos;
$info->listing->price = $postPreco;
$info->listing->property_type = $postTipo;
$info->listing->url = $postDirecionamento;
// save the updated document
$info->asXML('facebook.xml');
header('Location: index.php');
?>
And this is the XML (facebook.xml)
<?xml version="1.0" encoding="UTF-8"?>
<listings>
<title>Feed imóvel novo</title>
<link rel="self" href="http://www.onecia.com.br"/>
<listing>
<home_listing_id></home_listing_id>
<content_ids></content_ids>
<name></name>
<description></description>
<address format="simple">
<component name="city"> </component>
<component name="region">Rio Grande do Sul</component>
<component name="country">Brasil</component>
</address>
<neighborhood></neighborhood>
<image>
<url></url>
</image>
<num_baths></num_baths>
<num_beds></num_beds>
<price></price>
<property_type></property_type>
<url></url>
</listing>
</listings>
As you can see, in the XML i have this:
<address format="simple">
<component name="city"> </component>
<component name="region">Rio Grande do Sul</component>
<component name="country">Brasil</component>
</address>
The question is: How can i get this "city" component? For the other items, i just get the general tag link, but this atributes (format - simple, name - city) i don't know how to gather it by php.
I have this for base, how can i adapt it to gather only the city?
$info->listing->address->component = $postCidade;