将 xml 转换为 php
我需要帮助将以下 xml 转换为 php。有人可以帮助我吗?
PUT /feeds/default/private/full/resource_id/revisions/revision_number
Host: docs.google.com
GData-Version: 3.0
Authorization: <your authorization header here>
Content-Length: 722
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd='http://schemas.google.com/g/2005'xmlns:docs="http://schemas.google.com/docs/2007" gd:etag="W/"DkIBR3st7ImA9WxNbF0o."">
<id>https://docs.google.com/feeds/id/resource_id/revisions/1</id>
<updated>2009-08-17T04:22:10.440Z</updated>
<app:edited xmlns:app="http://www.w3.or /2007/app">2009-08-06T03:25:07.799Z</app:edited>
<title>Revision 1</title>
<content type="text/html" src="https://docs.google.com/feeds/download/document/ Export?docId=doc_id&revision=1"/>
<link rel="alternate" type="text/html" href="https://docs.google.com/Doc?id=doc_id&revision=1"/>
<link rel="self" type="application/atom+xml" href="https://docs.google.com/feeds/default/private/full/resource_id/revisions/1"/>
<author>
<name>user</name>
<email>[email protected]</email>
</author>
<docs:publish value="true"/>
<docs:publishAuto value="false"/>
</entry>
I need help in converting the following xml into php. Anyone can help me?
PUT /feeds/default/private/full/resource_id/revisions/revision_number
Host: docs.google.com
GData-Version: 3.0
Authorization: <your authorization header here>
Content-Length: 722
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd='http://schemas.google.com/g/2005'xmlns:docs="http://schemas.google.com/docs/2007" gd:etag="W/"DkIBR3st7ImA9WxNbF0o."">
<id>https://docs.google.com/feeds/id/resource_id/revisions/1</id>
<updated>2009-08-17T04:22:10.440Z</updated>
<app:edited xmlns:app="http://www.w3.or /2007/app">2009-08-06T03:25:07.799Z</app:edited>
<title>Revision 1</title>
<content type="text/html" src="https://docs.google.com/feeds/download/document/ Export?docId=doc_id&revision=1"/>
<link rel="alternate" type="text/html" href="https://docs.google.com/Doc?id=doc_id&revision=1"/>
<link rel="self" type="application/atom+xml" href="https://docs.google.com/feeds/default/private/full/resource_id/revisions/1"/>
<author>
<name>user</name>
<email>[email protected]</email>
</author>
<docs:publish value="true"/>
<docs:publishAuto value="false"/>
</entry>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看标准 PHP 类 simpleXML:PHP 手册
那里的例子应该对你有帮助弄清楚。
Have a look at standard PHP class simpleXML: PHP Manual
The examples there should help you figure it out.
您需要属性的值,而不是标签(标签为空)。您可以使用数组语法访问属性,例如:
echo $docsnode['value'];
或者您可以使用
attributes
方法,例如:命名空间混淆设置在 ;- )
不,这是一个命名空间元素,您必须使用
children
方法或使用 xpath 来获取那些元素(除非它们位于默认文档命名空间中,但这些节点不是)...或者
所以你的代码应该看起来像这样:
You want the value of an attribute, not the tag (which is empty). You can access attributes with array syntax for example:
echo $docsnode['value'];
or you can use the
attributes
method like:And the namespace confusion sets in ;-)
Nope thats a namespace elemtn you have to get at those using the
children
method or with xpath (unless they are in the default document namespace, but these nodes arent)...OR
So your code should look something like this: