Subwaydesigns
07-13-2007, 06:24 PM
Hello everybody,
There must be a very obvious answer to this. I am not especially well-versed in server side scripting, although I usually manage to get by... but this time I'm stuck.
Let me explain what I'm trying to do. I have an xml file for a gallery I am displaying in flash. I'm trying to build a CMS for this gallery - nothing much, just an upload/order/delete images utility.
Now, I use an XML parser class in php, that creates an object containing my xml nodes (with tags, subnodes, attributes etc.) as arrays. For example, say I have an xml file that looks like:
<images>
<pic>
<image>imageinfo</image>
<thumbn>thumbinfo</thumbn>
<caption>captioninfo</caption>
</pic>
</images>
I can access thumbinfo using $parser->document->pic[0]->thumbn[0]->tagData.
Ok, enough background. What I'm trying to do is very simple - I just want to add an element to the $parser->document->pic array (which will add a new node when the xml is generated).
Here's the code I'm using:
function newim() {
global $parser;
$parser->document->pic[0]->thumbn[0]->tagData = "original";
$parser->document->pic[3] = $parser->document->pic[0]; //the original pic array has 3 elements (pic[0], pic[1], pic[2]); I am adding a fourth.
$parser->document->pic[3]->thumbn[0]->tagData = "new";
echo $parser->document->pic[0]->thumbn[0]->tagData; //output: new
echo $parser->document->pic[3]->thumbn[0]->tagData; //output: new
}
can anyone explain this behavior? I would think that the value $parser->document->pic[0]->thumbn[0]->tagData never got changed - that is, I would expect this code to output "original" and then "new". I suspect it might have something to do with variable scope, but I've been fighting with this code all morning and I'm not getting anywhere.
Any ideas or insight you can provide would be greatly appreciated.
Marc
There must be a very obvious answer to this. I am not especially well-versed in server side scripting, although I usually manage to get by... but this time I'm stuck.
Let me explain what I'm trying to do. I have an xml file for a gallery I am displaying in flash. I'm trying to build a CMS for this gallery - nothing much, just an upload/order/delete images utility.
Now, I use an XML parser class in php, that creates an object containing my xml nodes (with tags, subnodes, attributes etc.) as arrays. For example, say I have an xml file that looks like:
<images>
<pic>
<image>imageinfo</image>
<thumbn>thumbinfo</thumbn>
<caption>captioninfo</caption>
</pic>
</images>
I can access thumbinfo using $parser->document->pic[0]->thumbn[0]->tagData.
Ok, enough background. What I'm trying to do is very simple - I just want to add an element to the $parser->document->pic array (which will add a new node when the xml is generated).
Here's the code I'm using:
function newim() {
global $parser;
$parser->document->pic[0]->thumbn[0]->tagData = "original";
$parser->document->pic[3] = $parser->document->pic[0]; //the original pic array has 3 elements (pic[0], pic[1], pic[2]); I am adding a fourth.
$parser->document->pic[3]->thumbn[0]->tagData = "new";
echo $parser->document->pic[0]->thumbn[0]->tagData; //output: new
echo $parser->document->pic[3]->thumbn[0]->tagData; //output: new
}
can anyone explain this behavior? I would think that the value $parser->document->pic[0]->thumbn[0]->tagData never got changed - that is, I would expect this code to output "original" and then "new". I suspect it might have something to do with variable scope, but I've been fighting with this code all morning and I'm not getting anywhere.
Any ideas or insight you can provide would be greatly appreciated.
Marc