I am trying to parse different links from an xml file. I read the docs and every post I found about parsing xml files but I didn't find a way to access nodes like I want. For example:
<link rel="self" type="text/html" title="title0" length="8359" href="http://example0.com"/>
<link rel="alternate" type="text/html" title="title1" length="8359" href="http://example3.com"/>
<link rel="related" type="text/html" title="title2" length="8359" href="http://example4.com"/>
<link rel="related" type="text/html" title="title3" length="8359" href="http://example4.com"/>
<link rel="related" type="text/html" title="title4" length="8359" href="http://example5.com"/>
<link rel="related" type="text/html" title="title5" length="8359" href="http://example5.com"/>
How can I access:
- The href of the link that has a rel="self" (return String).
- The href of the link that has a rel="alternate" (return String).
- The hrefs of the links that has a rel="related" (return Array).
Using SimpleXML:
$xml=simplexml_load_file('url_to_xml') or die('Error: Cannot create object');
...