Re: Object assignment
| From: | Matt Grimm | Date: | Wed, 09 Jul 2003 20:44:55 +0000 |
| Subject: | Re: Object assignment | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-154628@lists.php.net to get a copy of this message | ||
Tom:
Thanks for the help. Using the array setup you described, I end up with the
value of each "record" node being appended to a single instance of the
parent node. And that single instance of the parent node is the final one
that was parsed (the attributes verify this). The example I used below is
outputting this:
<rootElement>
<record id="2">Value 1Value 2</record>
</rootElement>
Any ideas?
--
Matt Grimm
Web Developer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Parkway
Anchorage, AK 99508
907.770.6200 ext. 686
907.336.6205 (fax)
E-mail: mgrimm@healthtvchannel.org
Web: www.healthtvchannel.org
"Tom Rogers" <trogers@kwikin.com> wrote in message
news:1218162094.20030709111505@kwikin.com...
> Hi,
>
> Wednesday, July 9, 2003, 10:38:22 AM, you wrote:
> MG> I'm having trouble creating objects with DOMXML. As I loop through a
level
> MG> of nodes, I'm creating a new element based on the array's key name.
The XML
> MG> might look like this:
>
> MG> <rootElement>
> MG> <record id="1">Value 1</record>
> MG> <record id="2">Value 2</record>
> MG> </rootElement>
>
> MG> So I'd be doing this with DOMXML in a loop:
>
> $thisChild = $doc->>create_element($key);
> MG> $thisChild = $ancestor->append_child($thisChild);
>
> MG> Where $key is 'record' in this example, and $ancestor is
'rootElement',
> MG> which is carried along in the function.
>
> MG> The problem that when I reach the second element by the same name, and
in
> MG> the same node level, I'm overwriting the $thisChild object that I just
> MG> created. How can I dynamically name these objects so that I can have
an
> MG> indeterminate number of elements by the same name, in the same level?
>
> What I have done is to keep an array of elements so it would work like
> this
>
> $elements = array();
>
> //loop
> if(!isset($elements[$key])){
> $elements[$key] = $doc->create_element($key);
> }
> $thisChild = $ancestor->append_child($elements[$key]);
> //end loop
>
> --
> regards,
> Tom
>