简体   繁体   English

解析Google联系人api XML

[英]parsing google contacts api XML

So I obtained contact data from Google in the form of the following jumble of XML: 因此,我以以下XML形式从Google获得了联系数据:

<entry gd:etag='&quot;Q3Y4fDVSLyt7I2A9WhJXFEkDTgY.&quot;'><id>http://www.google.com/m8/feeds/contacts/email/base/24fc18e00ee1c72e</id><updated>2012-08-08T18:18:42.834Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2012-08-08T18:18:42.834Z</app:edited><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/><title>Person 1</title><link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*' href='https://www.google.com/m8/feeds/photos/media/email/24fc18e00ee1c72e'/><link rel='self' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/email/full/24fc18e00ee1c72e'/><link rel='edit' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/email/full/24fc18e00ee1c72e'/><gd:name><gd:fullName>Person 1</gd:fullName><gd:givenName>Person</gd:givenName><gd:familyName>1</gd:familyName></gd:name><gd:email rel='http://schemas.google.com/g/2005#home' address='person1@person.com' primary='true'/><gContact:groupMembershipInfo deleted='false' href='http://www.google.com/m8/feeds/groups/email/base/6'/></entry><entry gd:etag='&quot;R30zcTVSLyt7I2A9WhJXFEkDTgc.&quot;'><id>http://www.google.com/m8/feeds/contacts/email/base/2c7cd0de89c805cc</id><updated>2012-08-08T18:18:56.389Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2012-08-08T18:18:56.389Z</app:edited><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/><title>Person 2</title><link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*' href='https://www.google.com/m8/feeds/photos/media/email/2c7cd0de89c805cc'/><link rel='self' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/email/full/2c7cd0de89c805cc'/><link rel='edit' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/email/full/2c7cd0de89c805cc'/><gd:name><gd:fullName>Person 2</gd:fullName><gd:givenName>Person</gd:givenName><gd:familyName>2</gd:familyName></gd:name><gd:email rel='http://schemas.google.com/g/2005#home' address='person2@person.com' primary='true'/><gContact:groupMembershipInfo deleted='false' href='http://www.google.com/m8/feeds/groups/email/base/6'/></entry>

How would I use domdocument to parse this XML in PHP to return a nice array in which each entry would contain the person's title, name, and email? 我将如何使用domdocument在PHP中解析此XML,以返回一个不错的数组,其中每个条目都将包含该人的标题,姓名和电子邮件?

I am lost as to which domdocument methods are appropriate to use in this scenario. 我不知道哪种domdocument方法适合在这种情况下使用。

Learn DOMXPath . 了解DOMXPath It's what you want. 这就是你想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM