Reputation: 115
Hi there I apologise now if this question has been asked and answered I have been working on this for what seems like days now and am stuck at the final hurdle and have got this far from reading through other posts on this site so hear goes ...
I have been working on a form that enters details into an xml file and I have another page that I require to show data from the xml file as long as it matches certain criteria .
Basic XML Structure
<information>
<entry>
<date></date>
<name></name>
<status></status>
<notes></notes>
<comments></comments>
</entry>
</information>
Basically I am using
$lib = simplexml_load_file("sample.xml");
$today = date("m/d/y");
$query = $lib->xpath("//information//date[contains(., '$today')] | //information//status[contains(., 'out')]");
foreach($query as $node){
echo "<div id='one'>$node->name</div>
<div id='two'>$node->notes</div>
<div id='three'><div class='front'>$node->comments</div></div>";
}
It Seems to print the amount of div's there should be but does not add any text for the values . Could some kind soul please point me in the right direction and once again I apologise if this has been answered and I also apologise if I have not been forthcoming enough with information .
Update : What I require this to do is query the xml file for entries that have today's date in date and out in status and then display name notes and comments from each one that matches the criteria and this will be used inside an if statement so if it matches it shows the data if not it shows another div thank you for any attempts you make .
Update 2 The Query I am running shows the results if either of the answers match I need it to return the data if it matches both thanks in advance.
Upvotes: 1
Views: 118
Reputation: 89285
If you want to select all <information>
tags having descendant tag <date>
with certain criteria or having descendant tag <status>
with certain criteria, your xpath syntax should be :
"//information[.//date[some criteria]] | //information[.//status[some criteria]]"
If I guessed what you are after correctly, your xpath query should be as follow :
$query = $lib->xpath("//information[.//date[contains(., '$today')]] | //information[.//status[contains(., 'out')]]");
PS: Change //information
to //entry
in case you want <entry>
tag instead of <information>
. BTW I know nothing about PHP, only interested in xpath part of this question.
Upvotes: 1