从 SimpleXMLElement 对象获取值
您好,我有以下 XML 片段:
......
<Result number="4" position="1" points="25">
<Driver driverId="button" url="http://en.wikipedia.org/wiki/Jenson_Button">
<GivenName>Jenson</GivenName>
<FamilyName>Button</FamilyName>
<DateOfBirth>1980-01-19</DateOfBirth>
<Nationality>British</Nationality>
</Driver>
......
我可以轻松使用以下内容来获取 GiveName:
$item->Driver->GivenName;
但是当我使用:
$item->Driver->FamilyName;
我得到 SimpleXMLElement Object ()
我环顾四周,发现这可能与将其传递给字符串有关但后来我在屏幕上什么也没看到。甚至没有 SimpleXMLElement 对象。
我不明白,因为它是 GiveName 的兄弟姐妹并且有效。
Hi I have this following segment of XML:
......
<Result number="4" position="1" points="25">
<Driver driverId="button" url="http://en.wikipedia.org/wiki/Jenson_Button">
<GivenName>Jenson</GivenName>
<FamilyName>Button</FamilyName>
<DateOfBirth>1980-01-19</DateOfBirth>
<Nationality>British</Nationality>
</Driver>
......
I can use the following easily to get the GivenName:
$item->Driver->GivenName;
But when I use:
$item->Driver->FamilyName;
I get SimpleXMLElement Object ()
I have looked around and found that it might be something to do with passing it to a string but then I get nothing on screen. Not even SimpleXMLElement Object.
I don't understand as it's a sibling of GivenName and that works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这两种情况下,您都会得到一个 SimpleXMLElement 对象,如果您使用 print_r(),您将看到该对象:
输出:
您可以使用显式转换来获取字符串形式的值:
You get a SimpleXMLElement object in both cases, which you'll see if you use print_r():
Outputs:
You can use an explicit cast to get the values as strings:
为了让 PHP 理解,你必须对对象进行强制类型转换,如下所示:
OUTPUT :
To make PHP understand you have to give typecasting forcefully on object like below:
OUTPUT :