开发者

SimpleDOM.php - Issues with sortedXPath

开发者 https://www.devze.com 2023-03-10 04:40 出处:网络
I have a little problem with the usage of SimpleDOM and sortedXPath. Given is the following XML Structure. I want to sort it either by row id, name or birthday.

I have a little problem with the usage of SimpleDOM and sortedXPath. Given is the following XML Structure. I want to sort it either by row id, name or birthday.

<table>
  <data>
    <row id="1">
      <column>Jimmy</column>
      <column>01/10/1977</column>
     </row>
     <row id="3">
       <column>Johnny</column>
       <column>04/01/2001</column>
     </row>
     <row id="2">
       <column>Tim</column>
       <column>13/02/1990</column>
     </row>
     <row id="4">
       <column>Paul</column>
       <column>13/02/1955</column>
     </row>
   </data>
</table>

Sorting by id turned out to be simple by using:

foreach($xmlObject->data->sortedXPath('row','@id', SORT_DESC) as $node)

so $node contains all rows and i can output them in the correct order. But i'm unable to order by name or date. I have tried:

foreach($xmlObject->data->sortedXP开发者_StackOverflowath('row','column[0]', SORT_DESC) as $node)
foreach($xmlObject->data->sortedXPath('row/column[0]','.', SORT_ASC) as $node)

but this creates either $nodes with just the value of column and in a strange oder or no output at all. Please help i'm stuck here for hours now :(

Regards


XPath counts 1-based.

foreach($xmlObject->data->sortedXPath('row','column[1]', SORT_DESC) as $node)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号