Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7488
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Problem creating XML file |
| Date | 2012-11-07 13:44 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <k7dokm$mbd$1@dont-email.me> (permalink) |
| References | <8f0cae0e-5acf-4ecb-bc9f-12e663bf4a49@googlegroups.com> |
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
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problem creating XML file dandi.box@gmail.com - 2012-11-07 04:42 -0800
Re: Problem creating XML file Denis McMahon <denismfmcmahon@gmail.com> - 2012-11-07 13:44 +0000
Re: Problem creating XML file dandi.box@gmail.com - 2012-11-07 08:21 -0800
Re: Problem creating XML file Denis McMahon <denismfmcmahon@gmail.com> - 2012-11-07 17:41 +0000
Re: Problem creating XML file dandi.box@gmail.com - 2012-11-07 14:51 -0800
Re: Problem creating XML file Michael Fesser <netizen@gmx.de> - 2012-11-08 01:50 +0100
csiph-web