开发者

Converting xml into php

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&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>user@gmail.com</email>
 </author>
 <docs:publish value="true"/>
 <docs:publishAuto value="false"/>
</entry>


Have a look at standard PHP class simpleXML: PHP Manual

The examples there should help you figure it out.


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'];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜