Jump to content

php xml trouble? dom newbie


prometheos

Recommended Posts

hi,

im having this annoying problem with parsing xml files i have and adding a node value to the <by> tag.

heres my xml layout:

<items>
    <item quantity="1">
    <itemSource>China</itemSource>
    <itemName>New Shoes </itemName>
    <description>New Kicks </description>
    <deliveryCity>Dublin </deliveryCity>
    <delivery>My House </delivery>
    <date>
       <day>04</day>
       <month>04</month>
       <year>2010</year>
    </date>
    <picSource>images/app.jpg</picSource>
    <requested>
       <by></by>
       <confirmed></confirmed>
    </requested>
  </item>
</items>

So say theres 3<item> instances in my xml, and ive selected 1 of them....

 

i want it so that if the item in the loop matches the item selected by the user, then a user id(say mine) is added to the by field of only the item they've selected...( they can select more than 1)

 

heres my code:

$dom = new DOMDocument();
			$dom->load($filename);
			$xpath = new DOMXPath($dom); 
			$itemNames = $xpath->query('item/itemName');
			$byPath = $xpath->query('item/requested/by');
			foreach($itemNames as $itemName){
				if(strcmp($itemName->nodeValue, $itemN)==0){
					echo $itemName->nodeValue;
					//echo $byPath[0]->nodeValue;
					foreach($byPath as $byP){
						$byP= $fbUser_id;    //this is the part im not sure about, it loops thru all <by>'s in each <item> in the xml file, when it shud only update the 1 where 'itemName' matches?
					}
				}
			}
			$dom->save($filename);

 

This has been wrecking my head for a good while, can any1 help or think of a way of doing this? any suggestions will be appreciated?

thanks!

Link to comment
https://forums.phpfreaks.com/topic/190592-php-xml-trouble-dom-newbie/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.