Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #7487 > unrolled thread

Problem creating XML file

Started bydandi.box@gmail.com
First post2012-11-07 04:42 -0800
Last post2012-11-08 01:50 +0100
Articles 6 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  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

#7487 — Problem creating XML file

Fromdandi.box@gmail.com
Date2012-11-07 04:42 -0800
SubjectProblem creating XML file
Message-ID<8f0cae0e-5acf-4ecb-bc9f-12e663bf4a49@googlegroups.com>
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)


Where is it my error?

Thanks

[toc] | [next] | [standalone]


#7488

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2012-11-07 13:44 +0000
Message-ID<k7dokm$mbd$1@dont-email.me>
In reply to#7487
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

[toc] | [prev] | [next] | [standalone]


#7489

Fromdandi.box@gmail.com
Date2012-11-07 08:21 -0800
Message-ID<846d3b8b-7732-4314-b1c7-45efd8f0b3bc@googlegroups.com>
In reply to#7488
Sorry but I don't know what you mean.

Do I've to change only this?

$docAzione->addChild('documento', $row_files{'fm_nomefile'}); 

with...?

Thanks

[toc] | [prev] | [next] | [standalone]


#7491

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2012-11-07 17:41 +0000
Message-ID<k7e6gu$obd$1@dont-email.me>
In reply to#7489
On Wed, 07 Nov 2012 08:21:47 -0800, dandi.box wrote:

> Sorry but I don't know what you mean.
> 
> Do I've to change only this?
> 
> $docAzione->addChild('documento', $row_files{'fm_nomefile'});
> 
> with...?

I gave an explanation of the task ("You want to add empty children and 
then set the "nome" attributes for each child.") and example of code to 
create a xml structure with a root node containing multiple child nodes 
with attributes, which seemed to be your requirement.

Perhaps you need to look at the php manual for the functions I used.

http://www.php.net/manual/en/simplexmlelement.construct.php
http://www.php.net/manual/en/simplexmlelement.addchild.php
http://www.php.net/manual/en/simplexmlelement.addattribute.php

(You may want to change the /en/ to your preferred language)

I'm not going to write your code (unless you pay my $$ rate), but I will 
point you towards the solution and give examples.

Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#7496

Fromdandi.box@gmail.com
Date2012-11-07 14:51 -0800
Message-ID<4ce6e0fa-d6d8-4214-8183-872ef8ce8113@googlegroups.com>
In reply to#7491
Why are you talking about to create an empty children?

I need this:

<docAzione> 
<documento nome="Prova1.txt" /> 
<documento nome="Prova2.txt" /> 
</docAzione> 

Why do you see "empty children"?

Thanks

[toc] | [prev] | [next] | [standalone]


#7498

FromMichael Fesser <netizen@gmx.de>
Date2012-11-08 01:50 +0100
Message-ID<gvvl981ev0jn9qigcs1p454cgsca6q6jfp@mfesser.de>
In reply to#7496
.oO(dandi.box@gmail.com)

>Why are you talking about to create an empty children?
>
>I need this:
>
><docAzione> 
><documento nome="Prova1.txt" /> 
><documento nome="Prova2.txt" /> 
></docAzione> 
>
>Why do you see "empty children"?

Because your <documento/> are empty children, they don't have any
content. 'nome' is an attribute, but the elements themselves are empty.

This is an empty element:

<foo/> or <foo></foo>

This is a non-empty element:

<foo>bar</foo>

So, for each row from your database, create an empty 'documento'
element, add a 'nome' attribute to it with the value from the DB and
then append the whole thing to the root 'docAzione' element.

Micha

-- 
http://mfesser.de/
Fotos | Blog | Flohmarkt

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web