Hello, Will you please help me to figure out how to create a patern for the following datas. So that using preg_match_all I can extract the the datas like catName , Id, Title, and Descriptiption. Thanks in advance <Category> <catName>Business to Business</catName> <item> <Id>25</Id> <Title> title will be here</Title> <Description>Descript will be here</Description> </item> <item> <Id>2</Id> <Title> title will be here</Title> <Description>Descript will be here</Description> </item> <item> <Id>5</Id> <Title> title will be here</Title> <Description>Descript will be here</Description> </item> </Category> <Category> <catName>Onother Category</catName> <item> <Id>5</Id> <Title>title will be here</Title> <Description>Descript will be here</Description> </item> <item> <Id>5</Id> <Title>title will be here</Title> <Description>Descript will be here</Description> </item> </Category> Code (markup): And so on
Yes I am using php 5 and I tried the following code <?php $xmlstr = simplexml_load_file('rssfeed.xml'); $xml = new SimpleXMLElement($xmlstr); foreach ($xml->Category as $category) { echo $category->catName, '<br />'; } ?> Code (markup): Just to test if it works but what I get is the following errors Warning: SimpleXMLElement::__construct() [function.--construct]: Entity: line 11: parser error : Start tag expected, '<' not found in /home/articnet/public_html/tools/latestnews.php on line 3 Warning: SimpleXMLElement::__construct() [function.--construct]: in /home/articnet/public_html/tools/latestnews.php on line 3 Warning: SimpleXMLElement::__construct() [function.--construct]: ^ in /home/articnet/public_html/tools/latestnews.php on line 3 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/articnet/public_html/tools/latestnews.php:3 Stack trace: #0 /home/articnet/public_html/tools/latestnews.php(3): SimpleXMLElement->__construct('??????????') #1 {main} thrown in /home/articnet/public_html/tools/latestnews.php on line 3 Code (markup):
I got banned for : http://forums.digitalpoint.com/showthread.php?p=2692071#post2692071 are you gonna write this dudes xml parser or am I ???
EDIT: Lol, makes sense. Aaand I think I just did. Even simpler: $xml = simplexml_load_file('rssfeed.xml'); foreach ($xml->item as $category) { echo $category->Id, '<br />'; echo $category->Title, '<br />'; echo $category->Description, '<br />'; } PHP: