FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Problem creating XML file
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Problem creating XML file [message #179557 is a reply to message #179556] Wed, 07 November 2012 13:44 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Wed, 07 Nov 2012 04:42:52 -0800, dandi.box wrote:

> I need to create this structure
>
> <docAzione>
> <documento nome="Prova1.txt" />
> <documento nome="Prova2.txt" />
> </docAzione>
>
> I tried doing:
>
> $docAzione = $azione->addChild('docAzione');
>
> while ($row_files = mysql_fetch_array($result_files,MYSQL_ASSOC)) {
>
> .....
>
> $docAzione->addChild('documento', $row_files{'fm_nomefile'});
>
>
> But result is:
>
> <docAzione>
> <documento>Prova1.txt</documento> <documento>Prova2.txt</documento>
> </docAzione>
>
> (wrong)
>
> So I tried with
>
> $docAzione->addAttribute('nome', $row_files{'fm_nomefile'});
>
> And I show:
>
> <docAzione nome="Prova1.txt"/>
>
> (wrong)

You want to add empty children and then set the "nome" attributes for
each child.

So maybe something like this:

<?php

$list = array( "jim", "susan", "henry" );

$p = new SimpleXMLElement( '<people></people>' );

foreach ( $list as $k => $d ) {

$c = $p->addChild( 'person' );
$c->addAttribute( 'name', $d );

}

echo $p->asXML();

?>

Output:

<?xml version="1.0"?>
<people><person name="jim"/><person name="susan"/><person name="henry"/></
people>

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How awesome Virtual Sailor 7 is
Next Topic: Order of Echoed HTML Output
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 05:21:21 GMT 2024

Total time taken to generate the page: 0.03249 seconds