将 xml 转换为 php

发布于 2024-10-25 20:40:36 字数 1435 浏览 4 评论 0原文

我需要帮助将以下 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&amp;revision=1"/>
 <link rel="alternate" type="text/html" href="https://docs.google.com/Doc?id=doc_id&amp;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独守阴晴ぅ圆缺 2024-11-01 20:40:36

看看标准 PHP 类 simpleXML:PHP 手册

那里的例子应该对你有帮助弄清楚。

Have a look at standard PHP class simpleXML: PHP Manual

The examples there should help you figure it out.

冷︶言冷语的世界 2024-11-01 20:40:36

关于如何做的任何想法怎么样
这部分?

您需要属性的值,而不是标签(标签为空)。您可以使用数组语法访问属性,例如:

echo $docsnode['value'];

或者您可以使用 attributes 方法,例如:

$attrs = $docsnode->attributes();
echo $attrs['value'];

命名空间混淆设置在 ;- )

所以我这么说对吗?
echo
$docs['发布']

不,这是一个命名空间元素,您必须使用 children 方法或使用 xpath 来获取那些元素(除非它们位于默认文档命名空间中,但这些节点不是)...

$ns = $xml->getNamespaces();
$docs = $xml->children($ns['docs']);
echo $docs->publish['value'];
echo $docs->publishAuto['value'];

或者

$docs = $xml->xpath('//docs:*');
echo $docs->publish['value'];
echo $docs->publishAuto['value'];

所以你的代码应该看起来像这样:

$ns = $feed->getNamespaces();

foreach($feed->entries as $entry)
{
  $docs = $entry->children($ns['docs']);
  $result = $docs->publish['value'];
}

how about for any idea how to do for
this portion?

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:

$attrs = $docsnode->attributes();
echo $attrs['value'];

And the namespace confusion sets in ;-)

so am i right to say that for
<docs:publish value="true"/> echo
$docs['publish']

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)...

$ns = $xml->getNamespaces();
$docs = $xml->children($ns['docs']);
echo $docs->publish['value'];
echo $docs->publishAuto['value'];

OR

$docs = $xml->xpath('//docs:*');
echo $docs->publish['value'];
echo $docs->publishAuto['value'];

So your code should look something like this:

$ns = $feed->getNamespaces();

foreach($feed->entries as $entry)
{
  $docs = $entry->children($ns['docs']);
  $result = $docs->publish['value'];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文