# Simple XML does not work - PlEASE HELP!

**URL:** <https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987>\
**Category:** programming\
**Created:** [May 11, 2008, 1:18pm UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987 "2008-05-11T13:18:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wispas](https://avatars.discourse-cdn.com/v4/letter/w/9de0a6/32.png) [@wispas](https://forum.kirupa.com/u/wispas)\
**Post date:** [May 11, 2008, 1:18pm UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/1 "2008-05-11T13:18:42Z")

</div>

I currently have this XML and simply want it displayed in the browser. I have tried using Simple XMl and it just does not seem to work - please help me think of something!!!

XML Code

> 

\<?xml version=“1.0” encoding=“UTF-8”?\>  
\<Total\_articles\>  
\<article titles=“Portfolio exhibition by new members of Association of Photographers” date=“February 2008” description=“I am participating in the Association of Photographers (AoP) annual “Portfolio” exhibition at the AoP Gallery. The exhibition is a platform for newcomers to the AoP to display their latest campaigns, assignments, commissions and personal projects. I will be exhibiting three pieces, including two new panoramic images from personal projects.” /\>

\<article titles=“Untitled 2007 group show of local commercial photographers” date=“December 2007” description=“Ten commercial photographers principally based in and around West London (myself included) are putting on a pre-Christmas show. Using the elegant function room of the George and Devonshire in Chiswick as a backdrop, this very eclectic mix of professionals – who work in fields as varied as architecture, portraiture, performance, still-life and fine-art – are displaying some of their best recent work.” /\>

\<article titles=“Granada trip” date=“November 2007” description=“Instead of a summer holiday this year, we went to Granada for an autumn break. The region is full of interesting things: the Sierra Nevada mountains and valleys, the alternative lifestyles on its slopes (including gypsy caves and new age traveller tepees), hills full of modern windmills and fields full of solar panels, old Wild West movie sets, and of course the amazing Alhambra.” /\>

\</Total\_articles\>

I have tried using the following bu does not work:

> 

\<?php

// define the url that will return the xml  
$xml\_url = ‘books.xml’;

// use this function to store the xml tree in a variable  
$sxml = simplexml\_load\_file($xml\_url);

// print the content of $sxml  
print\_($sxml);

// if you want to get particular values of the xml tree, use a loop  
foreach($var as $key=\>$value)  
{  
echo $key.‘=\>’.$value;  
echo ‘\<br /\>’;  
}  
?\>

This gives me the error:

**Fatal error** : Call to undefined function print\_() in **/homepages/25/d220261013/htdocs/xml/blogger.php** on line **10**

---

<div class="post-metadata">

**Author:** ![kitsunegari](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kitsunegari](https://forum.kirupa.com/u/kitsunegari)\
**Post date:** [May 11, 2008, 1:52pm UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/2 "2008-05-11T13:52:09Z")

</div>

use **[COLOR=Blue]print\_r[/COLOR]**

print\_ does not exist

---

<div class="post-metadata">

**Author:** ![wispas](https://avatars.discourse-cdn.com/v4/letter/w/9de0a6/32.png) [@wispas](https://forum.kirupa.com/u/wispas)\
**Post date:** [May 11, 2008, 5:56pm UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/3 "2008-05-11T17:56:43Z")

</div>

[quote=kitsunegari;2324642]use **[COLOR=Blue]print\_r[/COLOR]**

print\_ does not exist[/quote]

now i am getting this:

SimpleXMLElement Object ( [article] =\> SimpleXMLElement Object ( [@attributes] =\> Array ( [titles] =\> One day [date] =\> February 2008 [description] =\> Please work ) ) )  
**Warning** : Invalid argument supplied for foreach() in **/homepages/25/d220261013/htdocs/xml/blogger.php** on line \*\*13

\*\*It picks up the article but also gives some other stuff about simple xml as well.

---

<div class="post-metadata">

**Author:** ![kitsunegari](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kitsunegari](https://forum.kirupa.com/u/kitsunegari)\
**Post date:** [May 12, 2008, 7:10am UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/4 "2008-05-12T07:10:20Z")

</div>

$var is not declared in your code  
Use

```auto
foreach( **$sxml** as $key=>$value)

```

---

<div class="post-metadata">

**Author:** ![wispas](https://avatars.discourse-cdn.com/v4/letter/w/9de0a6/32.png) [@wispas](https://forum.kirupa.com/u/wispas)\
**Post date:** [May 12, 2008, 10:14am UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/5 "2008-05-12T10:14:01Z")

</div>

[quote=kitsunegari;2324931]$var is not declared in your code  
Use

```auto
foreach( **$sxml** as $key=>$value)

```

[/quote]

I managed to get the articles now, but why does it have these extra things like:

SimpleXMLElement Object ( [article] =\> Array ( [0]

I only want the title, date and description- how is that possible. BTW, thanks for the help.

> SimpleXMLElement Object ( [article] =\> Array ( [0] =\> SimpleXMLElement Object ( [@attributes] =\> Array ( [titles] =\> One day [date] =\> February 2008 [description] =\> This is the first article ) ) [1] =\> SimpleXMLElement Object ( [@attributes] =\> Array ( [titles] =\> Second day [date] =\> March 2008 [description] =\> This is the second article ) ) ) ) article=\>  
> article=\>

---

<div class="post-metadata">

**Author:** ![kitsunegari](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kitsunegari](https://forum.kirupa.com/u/kitsunegari)\
**Post date:** [May 12, 2008, 12:12pm UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/6 "2008-05-12T12:12:50Z")

</div>

```auto
foreach($sxml->article as $key=>$value)
{
   echo $value['titles'];
   echo '<br />';
   echo $value['date'];
   echo '<br />';
   echo $value['description'];
}

```

---

<div class="post-metadata">

**Author:** ![wispas](https://avatars.discourse-cdn.com/v4/letter/w/9de0a6/32.png) [@wispas](https://forum.kirupa.com/u/wispas)\
**Post date:** [May 12, 2008, 1:46pm UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/7 "2008-05-12T13:46:29Z")

</div>

> [@kitsunegari;2324997](#):
>
> ```auto
> foreach($sxml->article as $key=>$value)
> {
> echo $value['titles'];
> echo '<br />';
> echo $value['date'];
> echo '<br />';
> echo $value['description'];
> }
> 
> ```

thank you kitsunegari for all your help. you are a life saver. one more thing. if i put an image link in my articles.xml, how do i use simple xml to output it on screen to appear as an image?

I currently added a ‘arts’ link at the end:

> 

\<?xml version=“1.0” encoding=“utf-8”?\>  
\<Total\_articles\>  
\<article titles=“One day” dates=“February 2008” descriptions=“This is the first article” [COLOR=“Blue”]arts=“blog\_art/1.jpg”[/COLOR] /\>  
\<article titles=“Second day” dates=“March 2008” descriptions=“This is the second article” [COLOR=“blue”]arts=“blog\_art/2.jpg”[/COLOR] /\>  
\</Total\_articles\>

echo $value[‘arts’];  
\> this only shows me the link, but i want it to display as an image on screen.

---

<div class="post-metadata">

**Author:** ![simplistik](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/simplistik/32/7747_2.png) [@simplistik](https://forum.kirupa.com/u/simplistik)\
**Post date:** [May 12, 2008, 2:17pm UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/8 "2008-05-12T14:17:08Z")

</div>

[QUOTE=wispas;2325022]  
echo $value[‘arts’];  
\> this only shows me the link, but i want it to display as an image on screen.[/QUOTE]

just like you would in html …

```php

echo '<img src="'.$value['arts'].'" alt="" />';

```

---

<div class="post-metadata">

**Author:** ![kitsunegari](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kitsunegari](https://forum.kirupa.com/u/kitsunegari)\
**Post date:** [May 12, 2008, 3:05pm UTC](https://forum.kirupa.com/t/simple-xml-does-not-work-please-help/259987/9 "2008-05-12T15:05:00Z")

</div>

> thank you kitsunegari for all your help. you are a life saver.

you’re welcome 🙂
