simpleXML 循环条目
我有下面的 xml
<entry>
<id></id>
<title></title>
<dc:identifier></dc:identifier>
<dc:identifier></dc:identifier>
<dc:relation></dc:relation>
<dc:publisher></dc:publisher>
<dc:language xsi:type="dcterms:ISO639-2"></dc:language>
<dcterms:issued></dcterms:issued>
<updated></updated>
<rights></rights>
<author>
<name></name>
<uri></uri>
</author>
<link rel="alternate" href="" type="text/html"/>
<link rel="http://opds-spec.org/image" href="" type="image/jpeg"/>
<link rel="http://opds-spec.org/image/thumbnail" href="" type="image/jpeg"/>
<link rel="http://opds-spec.org/acquisition/buy" href="" type="application/epub+zip">
<opds:price currencycode="EUR"></opds:price>
</link>
<summary type="text"></summary>
</entry>
<entry>
<id></id>
<title></title>
<dc:identifier></dc:identifier>
<dc:identifier></dc:identifier>
<dc:relation></dc:relation>
<dc:publisher></dc:publisher>
<dc:language xsi:type="dcterms:ISO639-2"></dc:language>
<dcterms:issued></dcterms:issued>
<updated></updated>
<rights></rights>
<author>
<name></name>
<uri></uri>
</author>
<link rel="alternate" href="" type="text/html"/>
<link rel="http://opds-spec.org/image" href="" type="image/jpeg"/>
<link rel="http://opds-spec.org/image/thumbnail" href="" type="image/jpeg"/>
<link rel="http://opds-spec.org/acquisition/buy" href="" type="application/epub+zip">
<opds:price currencycode="EUR"></opds:price>
</link>
<summary type="text"></summary>
</entry>
......
我可以在解析所有项目时很好地解析它(simpleXML)
现在我想一次获取一个项目。所以我将一个 var 传递到我的文件,就像
file.php?start=1
file.php?start=2
etc
我尝试访问当前项目
$xml->entry[$start] returns NULL
或
$xml->entry->{$start} returns NULL
但两者都返回 NULL
我尝试直接访问它
$xml->entry[1]
$xml->entry->{1}
,它工作正常,
我错过了什么吗?
i have the xml below
<entry>
<id></id>
<title></title>
<dc:identifier></dc:identifier>
<dc:identifier></dc:identifier>
<dc:relation></dc:relation>
<dc:publisher></dc:publisher>
<dc:language xsi:type="dcterms:ISO639-2"></dc:language>
<dcterms:issued></dcterms:issued>
<updated></updated>
<rights></rights>
<author>
<name></name>
<uri></uri>
</author>
<link rel="alternate" href="" type="text/html"/>
<link rel="http://opds-spec.org/image" href="" type="image/jpeg"/>
<link rel="http://opds-spec.org/image/thumbnail" href="" type="image/jpeg"/>
<link rel="http://opds-spec.org/acquisition/buy" href="" type="application/epub+zip">
<opds:price currencycode="EUR"></opds:price>
</link>
<summary type="text"></summary>
</entry>
<entry>
<id></id>
<title></title>
<dc:identifier></dc:identifier>
<dc:identifier></dc:identifier>
<dc:relation></dc:relation>
<dc:publisher></dc:publisher>
<dc:language xsi:type="dcterms:ISO639-2"></dc:language>
<dcterms:issued></dcterms:issued>
<updated></updated>
<rights></rights>
<author>
<name></name>
<uri></uri>
</author>
<link rel="alternate" href="" type="text/html"/>
<link rel="http://opds-spec.org/image" href="" type="image/jpeg"/>
<link rel="http://opds-spec.org/image/thumbnail" href="" type="image/jpeg"/>
<link rel="http://opds-spec.org/acquisition/buy" href="" type="application/epub+zip">
<opds:price currencycode="EUR"></opds:price>
</link>
<summary type="text"></summary>
</entry>
......
I can parse it fine when parsing all items (simpleXML)
Now i want to get one item at the time.So i passing a var to my file like
file.php?start=1
file.php?start=2
etc
and i tried to access the current item
$xml->entry[$start] returns NULL
OR
$xml->entry->{$start} returns NULL
but both returns NULL
I tried to access it directly
$xml->entry[1]
$xml->entry->{1}
and its working fine
Am i missing somehthing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$_GET['start'] 可能不是正确的变量类型,请尝试将类型转换为整数。
$_GET['start'] is perhaps not proper variable type, try type casting to integer.
结果:
NULL
结果:
SimpleXMLElement 对象
(
[条目] => SimpleXMLElement 对象
(
[id] => 2
[标题] =>其他标题
)
)
Result:
NULL
Result:
SimpleXMLElement Object
(
[entry] => SimpleXMLElement Object
(
[id] => 2
[title] => The Other Title
)
)