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.
- 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
- Boil the URLs out of the sitemap.xml via XPath. (xpath:
//sitemap/loc
) - Resolve the inner XMLs and add them to a master document
- Gather the needed information from the master document (xpath:
//postname
)
精彩评论