0

我正在尝试访问 Taleo RSS/XML 提要并解析数据。我正在使用 SimpleXML,它正在正确加载所有常规数据,例如<title>,<link>等。

但是,有几个节点的格式类似于<taleo:reqId>or <taleo:location>,我似乎无法弄清楚如何访问该数据。SimpleXML 没有返回它。

`$xml = simplexml_load_file('https://chp.tbe.taleo.net/chp03/ats/servlet/Rss?org=DRAGADOS&cws=1&WebPage=SRCHR&WebVersion=0&_rss_version=2');`

在 Web 浏览器源中返回:

`<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://chp.tbe.taleo.net/chp03/ats/rss/taleorssfeed.xsl" ?>
<?xml-stylesheet type="text/css" href="https://chp.tbe.taleo.net/chp03/ats/rss/taleorssfeed.css" ?>
<rss xmlns:taleo="urn:TBERss" version="2.0">
<channel>
<title>Dragados Job Feed</title>
<link>https://chp.tbe.taleo.net/dispatcher/servlet/DispatcherServlet?org=DRAGADOS&amp;act=redirectCws&amp;cws=1</link>
<description>Dragados Job Feed</description>
<language>en</language>
<pubDate>Tue, 07 Nov 2017 17:00:40 GMT</pubDate>
<ttl>60</ttl>
<item>
<title>Estimator</title>
<link>https://chp.tbe.taleo.net/chp03/ats/careers/requisition.jsp?org=DRAGADOS&amp;cws=1&amp;rid=1155</link>
<guid>https://chp.tbe.taleo.net/chp03/ats/careers/requisition.jsp?org=DRAGADOS&amp;cws=1&amp;rid=1155</guid>
<description> ..... </description>
<pubDate>Tue, 07 Nov 2017 17:00:40 GMT</pubDate>
<taleo:reqId>1155</taleo:reqId>
<taleo:location>Southern California Branch (bidding)</taleo:location>
<taleo:locationCountry>US</taleo:locationCountry>
<taleo:locationState>US-CA</taleo:locationState>
<taleo:locationCity>Costa Mesa</taleo:locationCity>
<taleo:department>West Coast Bidding</taleo:department>
<taleo:html-description> ... </taleo:html-description>
</item>
...`

在 SimpleXML 中返回:

`object(SimpleXMLElement)#487 (2) { ["@attributes"]=> array(1) { ["version"]=> string(3) "2.0" } ["channel"]=> object(SimpleXMLElement)#486 (7) { ["title"]=> string(17) "Dragados Job Feed" ["link"]=> string(97) "https://chp.tbe.taleo.net/dispatcher/servlet/DispatcherServlet?org=DRAGADOS&act=redirectCws&cws=1" ["description"]=> string(17) "Dragados Job Feed" ["language"]=> string(2) "en" ["pubDate"]=> string(29) "Tue, 07 Nov 2017 17:00:40 GMT" ["ttl"]=> string(2) "60" ["item"]=> array(79) { [0]=> object(SimpleXMLElement)#485 (5) { ["title"]=> string(9) "Estimator" ["link"]=> string(87) "https://chp.tbe.taleo.net/chp03/ats/careers/requisition.jsp?org=DRAGADOS&cws=1&rid=1155" ["guid"]=> string(87) "https://chp.tbe.taleo.net/chp03/ats/careers/requisition.jsp?org=DRAGADOS&cws=1&rid=1155" ["description"]=> string(3580) " ...   " ["pubDate"]=> string(29) "Tue, 07 Nov 2017 17:00:40 GMT" }
...`
4

1 回答 1

0

在这种情况下,我发现有时将数据拆分为不同的命名空间更容易。因此,在浏览<item>数据时,您可以使用提取特定命名空间的所有元素(在本例中为“taleo”元素)->children('namespaceURN'),然后以与所有其他时间类似的方式访问数据,但使用这组新节点作为基础。

foreach ( $xml->channel as $channel )   {
    echo "title=".$channel->title.PHP_EOL;
    foreach ( $channel->item as $item ) {
        echo "pubDate=".$item->pubDate.PHP_EOL;
        // Extract the elements for taleo namespace
        $taleo = $item->children("urn:TBERss");
        echo "taleo:reqId=".$taleo->reqId.PHP_EOL;
    }
}
于 2017-11-14T09:47:22.197 回答