Google Apps脚本 - 如何从XmlDocument获取价值?

时间:2012-09-30 17:00:16

标签: google-apps-script

我正在尝试获取所有用户的所有日历详细信息。我成功地获得了这个,但它的返回结果是Xml格式如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://www.google.com/calendar/feeds/email-id/private/full</id>
  <updated>2012-02-15T15:34:49.000Z</updated>
  <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
  <title type="text">email-id</title>
  <subtitle type="text">email-id</subtitle>
  <link href="https://www.google.com/calendar/embed?src=email-id" rel="alternate" type="text/html"/>
  <link href="https://www.google.com/calendar/feeds/email-id/private/full" rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml"/>
  <link href="https://www.google.com/calendar/feeds/email-id/private/full" rel="http://schemas.google.com/g/2005#post" type="application/atom+xml"/>
  <link href="https://www.google.com/calendar/feeds/email-id/private/full/batch" rel="http://schemas.google.com/g/2005#batch" type="application/atom+xml"/>
  <link href="https://www.google.com/calendar/feeds/email-id/private/full?max-results=25" rel="self" type="application/atom+xml"/>
  <author>
    <name>Name</name>
    <email>email-id</email>
  </author>
  <generator uri="http://www.google.com/calendar" version="1.0">Google Calendar</generator>
  <openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:totalResults>
  <openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex>
  <openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage>
  <gCal:timezone value="Europe/Dublin" xmlns:gCal="http://schemas.google.com/gCal/2005"/>
  <gCal:timesCleaned value="0" xmlns:gCal="http://schemas.google.com/gCal/2005"/>

  <entry>
    <id>http://www.google.com/calendar/feeds/email-id/private/full/vj39u2qedgphrp10nah92h6ho0</id>
    <published>2012-02-15T11:21:54.000Z</published>
    <updated>2012-02-15T11:21:54.000Z</updated>
    <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
    <title type="text">Test Appointment</title>
    <content type="text">This is a test description</content>
    <link href="https://www.google.com/calendar/event?eid=dmozOXUycWVkZ3BocnAxMG5haDkyaDZobzAgcmFoaW1AZGFtc2" rel="alternate" title="alternate" type="text/html"/>
...

  </entry>
  </feed>

我想获得标题和内容的价值。请与我分享解决方案 谢谢

1 个答案:

答案 0 :(得分:3)

使用内置的Xml服务https://developers.google.com/apps-script/service_xml。 使用此服务,您可以通过xml文档进行解析。