Jump to content

prometheos

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

prometheos's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the reply, i realised that about the document class so i changed it to this and its working now! thanks here's what i have : $xmlDoc = new DOMDocument(); $xmlDoc->load($filename); if($experience=="Positive"){ $searchNode = $xmlDoc->getElementsByTagName("ratings"); $val += 1; $ratings = $searchNode->item(0); $ratings->setAttribute('stars', $val); }
  2. Hi, i have an xml in the following format (ratings as root). I want to increment the 'stars' attribute. <ratings stars="0"> <rating> <experience></experience> <comment></comment> </rating> </ratings> Here's what i have to increment the stars attribute, but it's not working? ($experience is a posted variable) $dom = new DOMDocument(); $dom->load($forfilename); if($experience=="Positive"){ $val += 1; $dom->setAttribute('stars', $val); }else{ $val -= 1; $dom->setAttribute('stars', $val); } $dom->save($forfilename); Can any1 help me :S this should work right? What am i missing? Thanks in advance
  3. thanks for the replies guyz il try that out now
  4. hey, im having trouble with this dom xpath query.... heres the layout of my xml <items> <item> <itemName> </itemName> <requested> <by> </by> <confirmed> </confirmed> </requested> </item> <item> </item> . . . </items> i want it so depending if the item name is a certain thing, to query the 'requested/by' field of that same item? can any1 help me? heres the code i have $dom = new DOMDocument(); $dom->load($forfilename); $xpath = new DOMXPath($dom); $a = $xpath->query('item/[itemName='.$itemN.']/../requested/by'); any ideas welcome, thanks in advance:)
  5. Hi wasn't sure where to post this as it contains html, js and php, i have 2 arrays of checkboxes and i want it so that when i check 1, the same index of the other 1 is unchecked... any ideas how to do this? here's the way i have it set up? if(($xml->item[$n-1]->requested->confirmed == "") &&($xml->item[$n-1]->requested->by != "") ){ //only display checkboxes if the items havnt been confirmed and theres a request to carry them echo '<td><center><input type="checkbox" name="confirmItems[]" value="'.$itemString.' onCheck = " " "/></center></td>'; echo '<td><center><input type="checkbox" name="denyItems[]" value="'.$itemString.'"/></center></td>'; } This is in a foreach loop... any ideas?
  6. it might be because $beste is only ever assigned a value once?
  7. Hi, i have 2 arrays of checkboxes and i want it so that when i check 1, the same index of the other 1 is unchecked... any ideas how to do this? here's the way i have it set up? if(($xml->item[$n-1]->requested->confirmed == "") &&($xml->item[$n-1]->requested->by != "") ){ echo '<td><center><input type="checkbox" name="confirmItems[]" value="'.$itemString.' onCheck = " " "/></center></td>'; echo '<td><center><input type="checkbox" name="denyItems[]" value="'.$itemString.'"/></center></td>'; } What should i do in the onCheck? this is inside a foreach loop by the way. thanks for the help
  8. try using the explode function http://ie.php.net/manual/en/function.explode.php
  9. hey thanks, i solved it..i just had to use an encoding that had the € symbol in it $delivery = htmlspecialchars($deliveryInput, null , 'ISO-8859-15'); thanks for the help:)
  10. you're welcome
  11. it might be because your only echoing the array and not a specific element in it. you could try looping through and printing out every element or a specific 1 try <?php $arr = $_GET['select2']; foreach( $arr as $a){ echo $a; } ?>
  12. Ok thanks i just tried that and got the same annoying error when i tried to display the xml :'( parsing error: undefined entity heres the part it highlights '<delivery><![CDATA[â¬]]></delivery>' its the 'â¬' part thats the problem..its just not understanding the € symbol... i took out the str_replace...shud i put it back in?
  13. Hi thanks for the quick reply. how do you mean? where specifically in my xml output? would it b like : $item->addChild("delivery", <![CDATA[$delivery]]>); and would that not ignore what text is typed in there?
  14. hi, i have a html form and one of the fields has to take in a currency symbol. so for example the € symbol in say the 'delivery' field.I then have to put this into an xml field but everytime i try, the xml file gives me a parsing error for undefined entity :-\ Heres a sample of what i have: $descriptionInput = $_POST['description']; $itemInput = $_POST['item_name']; $quantityInput = $_POST['quantity']; $deliveryCityInput = $_POST['deliveryCity']; $deliveryInput = $_POST['delivery']; $picSourceInput = $_POST['picSource']; $description = htmlentities($descriptionInput); $item_n = htmlentities($itemInput); $quantity = htmlentities($quantityInput); $deliveryCity = htmlentities($deliveryCityInput); $delivery = htmlentities($deliveryInput); $picSource = htmlentities($picSourceInput); $filename = "./xml_files/".$user_id.".xml"; $file = fopen ($filename, "r"); if (!$file){ $xml = simplexml_load_file(filename); $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<items></items>"; $items = simplexml_load_string($xmltext); $item = $items->addChild("item"); $item->addAttribute("quantity", $quantity); $item->addChild("itemSource",$source); $item->addChild("itemName",$item_n); $item->addChild("description", $description); $item->addChild("deliveryCity", $deliveryCity); $item->addChild("delivery", $delivery); It's been annoying me for awhile. i've tried str_replace on the $delivery string before its added to the xml with str_replace("€", "&#8364;",$delivery); But that still ends up the same way... Does anyone know how to get around this annoying error :'( Please help. any help is great Thanks
  15. 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!
×
×
  • 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.