XML Feed 获取打印值

发布于 2024-08-26 16:58:40 字数 5450 浏览 8 评论 0原文

这是我的提要:

 <entry>
    <id>http://api.visitmix.com/OData.svc/Sessions(guid'816995df-b09a-447a-9391-019512f643a0')</id>
    <title type="text">Building Web Applications with Microsoft SQL Azure</title>
    <summary type="text">SQL Azure provides a highly available and scalable relational database engine in the cloud. In this demo-intensive and interactive session, learn how to quickly build web applications with SQL Azure Databases and familiar web technologies. We demonstrate how you can quickly provision, build and populate a new SQL Azure database directly from your web browser. Also, see firsthand several new enhancements we are adding to SQL Azure based on the feedback we&#x2019;ve received from the community since launching the service earlier this year.</summary>
    <published>2010-01-25T00:00:00-05:00</published>
    <updated>2010-03-05T01:07:05-05:00</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Session" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Speakers" type="application/atom+xml;type=feed" title="Speakers" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Speakers">
      <m:inline>
        <feed>
          <title type="text">Speakers</title>
          <id>http://api.visitmix.com/OData.svc/Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Speakers</id>
          <updated>2010-03-25T11:56:06Z</updated>
          <link rel="self" title="Speakers" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Speakers" />
          <entry>
            <id>http://api.visitmix.com/OData.svc/Speakers(guid'3395ee85-d994-423c-a726-76b60a896d2a')</id>
            <title type="text">David-Robinson</title>
            <summary type="text"></summary>
            <updated>2010-03-25T11:56:06Z</updated>
            <author>
              <name>David Robinson</name>
            </author>
            <link rel="edit-media" title="Speaker" href="Speakers(guid'3395ee85-d994-423c-a726-76b60a896d2a')/$value" />
            <link rel="edit" title="Speaker" href="Speakers(guid'3395ee85-d994-423c-a726-76b60a896d2a')" />
            <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Sessions" type="application/atom+xml;type=feed" title="Sessions" href="Speakers(guid'3395ee85-d994-423c-a726-76b60a896d2a')/Sessions" />
            <category term="EventModel.Speaker" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
            <content type="image/jpeg" src="http://live.visitmix.com/Content/images/speakers/lrg/default.jpg" />
            <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
              <d:SpeakerID m:type="Edm.Guid">3395ee85-d994-423c-a726-76b60a896d2a</d:SpeakerID>
              <d:SpeakerFirstName>David</d:SpeakerFirstName>
              <d:SpeakerLastName>Robinson</d:SpeakerLastName>
              <d:LargeImage m:null="true"></d:LargeImage>
              <d:SmallImage m:null="true"></d:SmallImage>
              <d:Twitter m:null="true"></d:Twitter>
            </m:properties>
          </entry>
        </feed>
      </m:inline>
    </link>
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Tags" type="application/atom+xml;type=feed" title="Tags" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Tags" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Files" type="application/atom+xml;type=feed" title="Files" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Files" />
    <category term="EventModel.Session" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:SessionID m:type="Edm.Guid">816995df-b09a-447a-9391-019512f643a0</d:SessionID>
        <d:Location>Breakers L</d:Location>
        <d:Type>Seminar</d:Type>
        <d:Code>SVC07</d:Code>
        <d:StartTime m:type="Edm.DateTime">2010-03-17T12:00:00</d:StartTime>
        <d:EndTime m:type="Edm.DateTime">2010-03-17T13:00:00</d:EndTime>
        <d:Slug>SVC07</d:Slug>
        <d:CreatedDate m:type="Edm.DateTime">2010-01-26T18:14:24.687</d:CreatedDate>
        <d:SourceID m:type="Edm.Guid">cddca9b7-6830-4d06-af93-5fd87afb67b0</d:SourceID>
      </m:properties>
    </content>
  </entry>

我想打印:

我想我可以使用 filegetcontents 然后转换为 simplexmlstring,但我不知道如何获取我想要的更深层次的项目,例如作者和图像。

Here is my feed:

 <entry>
    <id>http://api.visitmix.com/OData.svc/Sessions(guid'816995df-b09a-447a-9391-019512f643a0')</id>
    <title type="text">Building Web Applications with Microsoft SQL Azure</title>
    <summary type="text">SQL Azure provides a highly available and scalable relational database engine in the cloud. In this demo-intensive and interactive session, learn how to quickly build web applications with SQL Azure Databases and familiar web technologies. We demonstrate how you can quickly provision, build and populate a new SQL Azure database directly from your web browser. Also, see firsthand several new enhancements we are adding to SQL Azure based on the feedback we’ve received from the community since launching the service earlier this year.</summary>
    <published>2010-01-25T00:00:00-05:00</published>
    <updated>2010-03-05T01:07:05-05:00</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Session" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Speakers" type="application/atom+xml;type=feed" title="Speakers" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Speakers">
      <m:inline>
        <feed>
          <title type="text">Speakers</title>
          <id>http://api.visitmix.com/OData.svc/Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Speakers</id>
          <updated>2010-03-25T11:56:06Z</updated>
          <link rel="self" title="Speakers" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Speakers" />
          <entry>
            <id>http://api.visitmix.com/OData.svc/Speakers(guid'3395ee85-d994-423c-a726-76b60a896d2a')</id>
            <title type="text">David-Robinson</title>
            <summary type="text"></summary>
            <updated>2010-03-25T11:56:06Z</updated>
            <author>
              <name>David Robinson</name>
            </author>
            <link rel="edit-media" title="Speaker" href="Speakers(guid'3395ee85-d994-423c-a726-76b60a896d2a')/$value" />
            <link rel="edit" title="Speaker" href="Speakers(guid'3395ee85-d994-423c-a726-76b60a896d2a')" />
            <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Sessions" type="application/atom+xml;type=feed" title="Sessions" href="Speakers(guid'3395ee85-d994-423c-a726-76b60a896d2a')/Sessions" />
            <category term="EventModel.Speaker" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
            <content type="image/jpeg" src="http://live.visitmix.com/Content/images/speakers/lrg/default.jpg" />
            <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
              <d:SpeakerID m:type="Edm.Guid">3395ee85-d994-423c-a726-76b60a896d2a</d:SpeakerID>
              <d:SpeakerFirstName>David</d:SpeakerFirstName>
              <d:SpeakerLastName>Robinson</d:SpeakerLastName>
              <d:LargeImage m:null="true"></d:LargeImage>
              <d:SmallImage m:null="true"></d:SmallImage>
              <d:Twitter m:null="true"></d:Twitter>
            </m:properties>
          </entry>
        </feed>
      </m:inline>
    </link>
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Tags" type="application/atom+xml;type=feed" title="Tags" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Tags" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Files" type="application/atom+xml;type=feed" title="Files" href="Sessions(guid'816995df-b09a-447a-9391-019512f643a0')/Files" />
    <category term="EventModel.Session" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:SessionID m:type="Edm.Guid">816995df-b09a-447a-9391-019512f643a0</d:SessionID>
        <d:Location>Breakers L</d:Location>
        <d:Type>Seminar</d:Type>
        <d:Code>SVC07</d:Code>
        <d:StartTime m:type="Edm.DateTime">2010-03-17T12:00:00</d:StartTime>
        <d:EndTime m:type="Edm.DateTime">2010-03-17T13:00:00</d:EndTime>
        <d:Slug>SVC07</d:Slug>
        <d:CreatedDate m:type="Edm.DateTime">2010-01-26T18:14:24.687</d:CreatedDate>
        <d:SourceID m:type="Edm.Guid">cddca9b7-6830-4d06-af93-5fd87afb67b0</d:SourceID>
      </m:properties>
    </content>
  </entry>

I want to print the:

I presume I can use filegetcontents and then transform to simplexmlstring, but I dont know how to get the deeper items in I want, like Author, and image.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

予囚 2024-09-02 16:58:40

考虑 SimpleXML 使用以下方式加载 XML 数据:

  • 属性对象的数组
  • 键值的类似

这样的事情应该可以解决问题:

$string = <<<STR
<entry>
    ...
  </entry>
STR;

$xml = @simplexml_load_string($string);

echo (string)$xml->title . '<br />';
echo (string)$xml->link[1]->inline->feed->entry->author->name . '<br />';
echo (string)$xml->content->properties->Location . '<br />';
echo (string)$xml->link[1]->inline->feed->entry->content['src'] . '<br />';

我得到以下输出:

Building Web Applications with Microsoft SQL Azure
David Robinson
Breakers L
http://live.visitmix.com/Content/images/speakers/lrg/default.jpg

在使用 SimpleXML 时,使用 var_dump($xml); 可以帮助您了解数据的表示方式——使访问数据变得更加容易;-)

注意:在这里,我使用了 @ 运算符 来抑制我在使用 simplexml_load_string 时收到的警告;否则,我有很多这样的警告:

Warning: simplexml_load_string() [function.simplexml-load-string]: 
   namespace error : Namespace prefix m on inline is not defined

Warning: simplexml_load_string() [function.simplexml-load-string]: <m:inline>

也许这里有什么需要修复的地方?

Considering SimpleXML loads XML data using :

  • array keys for attributes
  • objects for values

Something like this should do the trick :

$string = <<<STR
<entry>
    ...
  </entry>
STR;

$xml = @simplexml_load_string($string);

echo (string)$xml->title . '<br />';
echo (string)$xml->link[1]->inline->feed->entry->author->name . '<br />';
echo (string)$xml->content->properties->Location . '<br />';
echo (string)$xml->link[1]->inline->feed->entry->content['src'] . '<br />';

And I get the following output :

Building Web Applications with Microsoft SQL Azure
David Robinson
Breakers L
http://live.visitmix.com/Content/images/speakers/lrg/default.jpg

Using var_dump($xml); can help you find out how your data is represented, when using SimpleXML -- makes things easier when it comes to accessing it ;-)

Note : here, I've used the @ operator to supress the warnings I was getting when using simplexml_load_string ; else, I have plenty of warnings like these :

Warning: simplexml_load_string() [function.simplexml-load-string]: 
   namespace error : Namespace prefix m on inline is not defined

Warning: simplexml_load_string() [function.simplexml-load-string]: <m:inline>

Maybe there's something that needs fixing, here ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文