Jerred121 Posted November 24, 2010 Share Posted November 24, 2010 I'm trying to add/update an xml like so: $xml->Header->Record->$curblk->$row = $value; where $curblk and $row are obviously nodes. Problem is that sometimes I need to add/update nodes of the same name so I tried this: $xml->Header->Record->$curblk->$row[$multi] = $value; where $multi would represent the number (or instance or key?) of that node I wish to add/update. Issue with that is, php thinks that I'm tring to set the node as an array, which is not possible! So how do I dynamically add/update $row[0] , $row[1] , $row[2] base on the two variable, $row and $multi? ie: $row = Jim Bob; $multi = 0; <author>Jim Bob</author> $row = Tom Reed; $multi = 1; <author>Tom Reed</author> You get: <book> <author>Jim Bob</author> <author>Tom Reed</author> </book> Of course there is muuuuch more to it than that, but that is about as simple as I can explain it... Of course thank you for any help, i've been stuck on this for 3 days now! and my boss is not happy, especially since I'm a vary novice developer that took on this assignment... Link to comment https://forums.phpfreaks.com/topic/219715-two-variables-one-node/ Share on other sites More sharing options...
Jerred121 Posted November 24, 2010 Author Share Posted November 24, 2010 So basically what I'm asking is - how do I get the effect of something like: $xml->Header->Record->Node[2] = $value; but using dynamic variables to provide the node's name ($row="Node") and the node's key number ($multi=2)? Is this even possible? Or will I have to use another method of writing xmls? Link to comment https://forums.phpfreaks.com/topic/219715-two-variables-one-node/#findComment-1139154 Share on other sites More sharing options...
objnoob Posted November 24, 2010 Share Posted November 24, 2010 What class are you using? Link to comment https://forums.phpfreaks.com/topic/219715-two-variables-one-node/#findComment-1139160 Share on other sites More sharing options...
Jerred121 Posted November 24, 2010 Author Share Posted November 24, 2010 I'm using simplexml extension Link to comment https://forums.phpfreaks.com/topic/219715-two-variables-one-node/#findComment-1139164 Share on other sites More sharing options...
Jerred121 Posted November 24, 2010 Author Share Posted November 24, 2010 Since I can figure this out with the code I have in place, I guess I'm off to go write well over 300 lines of additional code... Link to comment https://forums.phpfreaks.com/topic/219715-two-variables-one-node/#findComment-1139218 Share on other sites More sharing options...
Anti-Moronic Posted November 25, 2010 Share Posted November 25, 2010 What about if you tried to create a string representation - like: $customNode = $row.'['.$multi.']'; Then use $customNode to refer to it instead. EDIT: To be honest, I'm shooting in the dark here. I've not used simplexml much. Only other suggestion is bump the thread couple more times if the above doesn't work, and also ask on stackoverflow.com. If all else fails, use a different class or make a small extension to simplexml to manage this add/update style. Link to comment https://forums.phpfreaks.com/topic/219715-two-variables-one-node/#findComment-1139322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.