Jump to content

Php Xml


Jamesking56
 Share

Recommended Posts

Can someone make an XML Parser for me because I just can't do it!I have a 'Latest News' XML file generated by my Support Center for my website, I want to integrate this into my website but I am having troubles.Here is the link for the XML file: XML FILE.It needs to have the ITEMS ONLY! not the first one as that is not an item.I want to have the page display like below:

<h5><a href="LINK HERE">TITLE HERE</a></h5><p>DESCRIPTION HERE</p>

Can you help me please?

Link to comment
Share on other sites

Have you looked through the XML DOM tutorial?You can apply XML DOM to PHP with the DOMDocument object:

// Create an instance of a DOMDocument object$doc = new DOMDocument();// Load the file$doc->load("file.xml");// Select <item> elements$items = $doc->getElementsByTagName("item");foreach($items as $item) {  // For every item get the information...  $link = $item->getElementsByTagName("link")->item(0)->firstChild->nodeValue;  $desc = $item->getElementsByTagName("description")->item(0)->firstChild->nodeValue;  $title = $item->getElementsByTagName("title")->item(0)->firstChild->nodeValue;  // ...and display it as desired  echo "<h5><a href=\"{$link}\">{$title}</a></h5>";  echo "<p>{$desc}</p>";}

Don't just copy the code, it might not work correctly, as I haven't tested it. Try to understand how it works.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...