Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

fabiom2211

[Resolvido] Criar arquivo XML a partir de uma Consulta de um Arqu

Recommended Posts

Fiz uma consulta do arquivo XML com php...

A partir dessa consulta quero criar um arquivo xml...

Eu consigo criar o arquivo xml...mais não to conseguindo colocar as variaveis no arquivo xml

Código:


<?php
echo '-----[ Usando XMLReader ]-----<br>' , PHP_EOL;

$xmll = new XMLReader();
$xmll->open( 'mes_qtd.xml' );

$manipulador_arq = fopen("fabio.xml","w+");


@fwrite($manipulador_arq,"<graph caption='Total de Quantidade' subcaption='Vendida no Mes' xAxisName='Mes' yAxisName='Quantidade'   numberPrefix=''>");


while ( $xmll->read() ){
       if ( ( $xmll->nodeType == XMLReader::ELEMENT ) && ( $xmll->name == 'set' ) ){

               echo 'name="' , $xmll->getAttribute( 'name' ) ;
               echo '"', PHP_EOL;
               echo 'value="' , $xmll->getAttribute( 'value' );
               echo '"', PHP_EOL;
               echo 'link="' , $xmll->getAttribute( 'link' ) ;
               echo '"', PHP_EOL;
               echo '<br>' , PHP_EOL;

       $xml = "<set   ";
       //$xml .= "name= getAttribute( 'name' )  ";
       //$xml .= "value= getAttribute( 'value' )  ";
       //$xml .= "link=getAttribute( 'link' )   ";
       $xml .= " />  ";

       @fwrite($manipulador_arq,$xml);
       $xml = "\n \n";


       }
}
?>

 

A parte que está comentada no meu código é a parte que escreve no arquivo xml

mais isso não funciona...

alguem sabe como posso escrever no arquivo xml as variaveis de consulta??

 

 

Att, Fabio

Compartilhar este post


Link para o post
Compartilhar em outros sites

ok...vou ver...abraço

 

Não conseguir resolver o meu problema...=/

 

 

Att, Fabio

 

Valeuu João Batista Neto

Já conseguir resolver o meu problema..

 

embaixo tá o código correto...

Att, Fabio

 

<?php
echo '-----[ Usando XMLReader ]-----<br>' , PHP_EOL;

$xmll = new XMLReader();
$xmll->open( 'mes_qtd.xml' );

$manipulador_arq = fopen("fabio.xml","w+");


@fwrite($manipulador_arq,"<graph caption='Total de Quantidade' subcaption='Vendida no Mes' xAxisName='Mes' yAxisName='Quantidade'   numberPrefix=''>");


while ( $xmll->read() ){
       if ( ( $xmll->nodeType == XMLReader::ELEMENT ) && ( $xmll->name == 'set' ) ){

       $name = $xmll->getAttribute( 'name' );
       $value = $xmll->getAttribute( 'value' );        

       $xml = "<set   ";
       $xml .= "name='$name' ";
       $xml .= "value='$value' ";
       $xml .= " />  ";

       @fwrite($manipulador_arq,$xml);
       $xml = "\n \n";
       }

}
@fwrite($manipulador_arq,"\n\n</graph>");
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Já conseguir resolver o meu problema..

 

Legal que você tenha conseguido, estou marcando o tópico como resolvido, caso tenha novas dúvidas, volte a postar.

 

Apenas por motivo de ilustração, se você tivesse optado por utilizar a XMLWriter em conjunto com a XMLReader, seu código ficaria assim:

 

$read = new XMLReader();
$read->open( 'read.xml' ); //Lendo a partir do arquivo read.xml

$write = new XMLWriter();
$write->openURI( 'write.xml' ); //Gravando no arquivo write.xml
$write->startDocument( '1.0' , 'UTF-8' );
$write->setIndent( true );
$write->setIndentString( "\t" );
$write->startElement( 'graph' );
$write->startAttribute( 'caption' ); $write->text( 'Total de Quantidade' ); $write->endAttribute();
$write->startAttribute( 'subcaption' ); $write->text( 'Vendida no Mes' ); $write->endAttribute();
$write->startAttribute( 'xAxisName' ); $write->text( 'Mes' ); $write->endAttribute();
$write->startAttribute( 'yAxisName' ); $write->text( 'Quantidade' ); $write->endAttribute();
$write->startAttribute( 'numberPrefix' ); $write->text( '' ); $write->endAttribute();

while ( $read->read() ){
if ( ( $read->nodeType == XMLReader::ELEMENT ) && ( $read->name == 'set' ) ){
	$write->startElement( 'set' );
	$write->startAttribute( 'name' ); $write->text( $read->getAttribute( 'name' ) ); $write->endAttribute();
	$write->startAttribute( 'value' ); $write->text( $read->getAttribute( 'value' ) ); $write->endAttribute();
	$write->endElement();
}
}

$write->endElement();

 

;)

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.