У меня возникли некоторые проблемы, заставляющие это работать, у меня есть массивная XML-лента, которую я помещаю в базу данных MYSQL с помощью PHP.
Одна статья XML выглядит следующим образом ...
<Article Created="10:49:51" ID="800737873">
<Heading>Week in review: Mobile, Google+ and Facebook grab headlines</Heading>
<Date>23/09/2011</Date>
- <Contents>
- <![CDATA[ This week NewsReach has been busy at ad:tech, speaking to lots of people about how we can help websites with targeted online newsfeeds, landing pages and other copy.<br/><br/>But we still found time to keep our finger on the pulse of the wider digital world and bring those stories straight to our readers.<br/><br/>This week saw a big focus on mobile marketing, with several industry commentators highlighting the importance of the channel for online communications.<br/><br/><promo>At NewsReach we can provide quality content for all online marketing platforms - call Jacey on 02075172240 to learn more.</promo>Digital trainer <a href="http://www.newsreach.co.uk/nr/online-marketing/marketings-future-is-mobile">Rob Thurner noted</a> that mobile allows businesses to "unlock new segments of consumers", while research by Head London highlighted the importance of good mobile websites.<br/><br/><a href="http://www.newsreach.co.uk/nr/online-marketing/mobile-websites-should-aid-integrated-experience">Report authors suggested</a> that mobile websites should not simply copy the desktop version's content and functionality, but should be designed in line with what mobile users want.<br/><br/>Mobile devices, in particular smartphones, are integral to young adults, according to a <a href="http://www.newsreach.co.uk/nr/online-marketing/internet-integral-to-young-consumers">study by Cisco</a>. The telecoms systems provider found under-30s regard it as vitally important to be able to access the internet on the go.<br/><br/>After about two months in limited field trial stage, <a href="http://www.newsreach.co.uk/nr/social-media-marketing/google-opens-doors-and-rolls-out-search">Google+ is now available to anyone</a> who wants to sign up. Google also rolled out a new search function, which will allow users to get personalised web search results within the social network.<br/><br/>And after much speculation, <a href="http://www.directnews.co.uk/news/facebook-overhauls-profiles-with-timeline-$21378257.htm">Facebook announced yesterday</a> that it will overhaul users' profile pages by introducing a virtual scrapbook that allows members to chronicle their life in one place. <br/><br/><em>Written by <a href="http://uk.linkedin.com/in/karenwebber">Karen Webber</a>, Deputy Head of News Feeds</em>
]]>
</Contents>
- <Summary>
- <![CDATA[ The future is mobile, while social networks continue their battle for supremacy.
]]>
</Summary>
- <Picture Orientation="Landscape" PhotoTag="Mobile, Google+ and Facebook grab headlines" Ratio="1.00" PhotoID="7036189">
<PhotoTag>Mobile, Google+ and Facebook grab headlines</PhotoTag>
- <Large Width="500" Height="500">
<URL>http://pictures.directnews.co.uk/liveimages/mobile+google+and+facebook+grab+headlines_3166_800737873_1_0_7036189_500.jpg</URL>
</Large>
- <Medium Width="300" Height="300">
<URL>http://pictures.directnews.co.uk/liveimages/mobile+google+and+facebook+grab+headlines_3166_800737873_1_0_7036189_300.jpg</URL>
</Medium>
- <Small Width="100" Height="100">
<URL>http://pictures.directnews.co.uk/liveimages/mobile+google+and+facebook+grab+headlines_3166_800737873_1_0_7036189_100.jpg</URL>
</Small>
</Picture>
- <Categories>
<Category ID="800089637">Online Marketing</Category>
<Category ID="800089646">ZHEADER</Category>
<Category ID="800092440">ZREVIEW</Category>
</Categories>
</Article>
Часть, о которой я хочу поговорить, это:
- <Categories>
<Category ID="800089637">Online Marketing</Category>
<Category ID="800089646">ZHEADER</Category>
<Category ID="800092440">ZREVIEW</Category>
</Categories>
Как видите, у меня есть 3 категории и 3 атрибута ID. При получении данных с использованием этого метода:
$feed = new SimpleXMLElement('newsreacharchive2011.xml', null, true);
foreach($feed as $article) // loop through
{
$category = mysql_real_escape_string("{$article->Categories->Category}");
$categoryID = mysql_real_escape_string("{$article->Categories->Category['ID']}");
}
Я получаю только 1-ю из 3-х категорий, поэтому мне нужна помощь в получении следующих двух категорий, я не знаю, нужно ли мне делать цикл while в цикле foreach, чтобы получить их или что, но я застрял, так что я надеюсь, что кто-то может помочь.
Спасибо.
------- РАСШИРЕНИЕ -------
Я только что попробовал это
$feed = new SimpleXMLElement('newsreacharchive2011.xml', null, true);
foreach($feed as $article) // loop through
{
$i = 0;
while($i < 3)
{
$category[$i] = mysql_real_escape_string("{$article->Categories->Category}");
$categoryID[$i] = mysql_real_escape_string("{$article->Categories->Category['ID']}");
$i++;
}
}
и все равно не работает