Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I need to display values of <code>&lt;numberofresults&gt;</code> &amp; <code>&lt;chargeablerateinfo&gt;</code> node in xpath or simpleXML plz give me how to access those elements.</p> </blockquote> <p><strong>In the provided XML document there is no element named <code>numberofresults</code></strong> -- you probably mean <code>numberOfAdults</code>.</p> <p><strong>This XPath expression</strong>:</p> <pre><code>//RateInfo/RoomGroup/Room </code></pre> <p>selects any <code>Room</code> element that is a child of a <code>RoomGroup</code> that is a child of any <code>RateInfo</code> element in the XML document.</p> <p><strong>This XPath expression</strong>:</p> <pre><code>//RateInfo/RoomGroup/Room/numberOfAdults </code></pre> <p>selects the <code>numberOfAdults</code> children of the elements selected by the previous expression.</p> <p><strong>And this XPath expression</strong>:</p> <pre><code>//RateInfo/ChargeableRateInfo </code></pre> <p>selects the <code>ChargeableRateInfo</code> element associated with a <code>RoomGroup</code></p> <p><strong>So, in your code you might want to do something like this</strong>:</p> <pre><code>$xml = simplexml_load_file("test.xml"); $rateInfos = $xml-&gt;xpath('//RateInfo'); foreach ($rateInfos as $rateInfo) { $rooms = $rateInfo-&gt;xpath('RoomGroup/Room'); foreach ($rooms as $room) { echo $room-&gt;numberOfAdults; } $chargeableRateInfo = $rateInfo-&gt;xpath('ChargeableRateInfo'); // Do whatever is wanted with $chargeableRateInfo } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload