开发者

Two tier xml feeds, get data from xml link

I use the new wordpress plugin, google xml sitemap.

Hello, lets say I have 100 posts. My sitemap xml file, instead of having 100 entries on it, has 5 links, each link linking to 20 posts.

What I'm trying to do.. is get every na开发者_C百科me of the post into a file on my server.

  1. The sitemap.xml has this schema: <>sitemap ... <>category_location

The loc represents the 5 links, each linking to another xml file with this schema: <>url ... <>post_name

Now, if I wanted to accest the category of links I'd do something like this:

$sitemap_feed = 'http://www.mysite.com/sitemap.xml';

$sitemap_xml = simplexml_load_file($sitemap_feed);

foreach( $sitemap_xml->sitemap as $xml){

$cat_location = $xml->category_location;

}

Now, I'd have to store all the category locations in an array, and run this code again to actually get my posts names.

$postname_xml = simplexml_load_file($cat_location);

foreach( $postname_xml->postname as $postname_xml){

$postname = $postname_xml->postname;

}

Is there a way to do it directly? something more elegant?

Thank you! Hope you can understand my question:(


You could use XPath to filter the data directly from the XML. If you could link me the XML I may be able to assist you a little bit with coding.

XPath @ Wikipedia
Xpath explained

Seeing your problem as resolving XML files which are mentioned inside an XML file I didn't find an easy solution on the web.

I'd go with following steps

  1. Boil the URLs out of the sitemap.xml via XPath. (xpath: //sitemap/loc)
  2. Resolve the inner XMLs and add them to a master document
  3. Gather the needed information from the master document (xpath: //postname)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜