开发者

simplexml path by index

I'm parsing simplexml and normally my simple xml would look like this

        $sig_size = (int)$xmlObject->sig->points;

which returns 24 in this example

 <?xml version='1.0' standalone='yes'?>
 <photo id='470'>
    <artist>mg</artist>
    <lines>
        <points>22</points>
        <angle>-5</angle>
        <x>165</x>
        <align>center</align>
        <color>ffffff</color>
    </lines>
    <sig>
        <padding>35</padding>
        <x>175</x>
        <y>300</y>
        <points>24</points>
        <angle>-5</angle>
        <align>center</align>
        <color>ffffff</color>
    </sig>
 </photo>

now I want to add a second sig item and refeence it by the index so the xml would look like this

 <?xml version='1.0' standalone='yes'?>
 <photo id='470'>
    <artist>mg</artist>
    <lines>
        <points>22</points>
        <angle>-5</angle>
        <x>165</x>
        <align>center</align>
        <color>ffffff</color>
    </lines>
    <sig>
        <padding>35</padding>
        <x>175</x>
        <y>300</y>
        <points>24</points>
        <angle>-5</angle>
        <align>center</align>
        <color>ffffff</color>
    </sig>
    <sig>
        <padding>35</padding>
        开发者_C百科<x>175</x>
        <y>300</y>
        <points>10</points>
        <angle>-5</angle>
        <align>center</align>
        <color>ffffff</color>
    </sig>
 </photo>

so how do I re-write the php line to get it by index


You would have to use brackets []:

$sig_size_one = (int)$xmlObject->sig[0]->points;
$sig_size_two = (int)$xmlObject->sig[1]->points;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜