Problem with SimpleDOM and sortedXPath
i have this XML structure:
<album _mngid="1">
<contentxmlurl>alb_1.xml</contentxmlurl>
<contentnumber>15</contentnumber>
<thumb>
<url>albthumbs/albth_1.jpg</url>
</thumb>
</album>
<album _mngid="2">
<contentxmlurl>alb_2.xml</contentxmlurl>
<contentnumber>35</contentnumber>
<thumb>
<url>albthumbs/albth_2.jpg</url>
</thumb>
</album>
<album _mngid="3">
<contentxmlurl>alb_3.xml</contentxmlurl>
<contentnumber>3</contentnumber>
<thumb>
<url>albthumbs/albth_3.jpg</url>
开发者_StackOverflow中文版</thumb>
</album>
I'd like to order di XML file by the evalue of '_mngid' attribute, but i have a lot of problem.. :(
The best that i've tryed is: foreach($xml->sortedXPath('collection/album','/@_mngid', SORT_DESC) as $album) {
but i obtain this order: 1,2,12,3,10,4,14,5,9,6,11,7,13,8,15 (in the XML file i have now 15 items).
Can u help me please to understand the right way?
Thanks very very much! bye bye
You are using /@_mngid
, which corresponds to the root node. If you want to select the current node's attribute, use @_mngid
. For instance:
foreach($xml->sortedXPath('collection/album','@_mngid', SORT_DESC) as $album) {
精彩评论