0

我有以下xml

<django-objects version="1.0">
<object pk="4613" model="customers.customer">
<field type="CharField" name="username">User A</field>
<field type="CharField" name="email"/>
<field type="BooleanField" name="activo">1</field>
<field type="CharField" name="address">street zz</field>
</object>
<object pk="4644" model="customers.customer">
<field type="CharField" name="username">User B</field>
<field type="CharField" name="email"/>
<field type="BooleanField" name="activo">1</field>
<field type="CharField" name="address">street bla bla</field>
</object>

尝试使用解析它

$xml = simplexml_load_string($url);

接着

foreach ($xml->object as $dato) { print_r($dato['pk']); }

工作正常..但我需要提取用户名...我该怎么做?

4

1 回答 1

0

您应该能够使用以下内容获取用户名;

foreach ($xml->object as $dato) {
    echo $dato->field[0];

}

当您遍历每个对象时,您希望获取每个对象的第一个字段元素。

于 2013-10-11T15:23:51.127 回答