You are here: SimpleXML question « PHP Programming Language « IT news, forums, messages
SimpleXML question

Posted by Andy on 01/28/07 12:47

Hi,

I'm running in to a little issue with SimpleXML, and wondered if
anyone knew if it was normal implementation for SimpleXML, or I'm not
using a correct flag, or even it's a an issue that should be
resolved. I'm actually only just starting to use SimpleXML with any
vigor, so I may well be mistaken about what I think it should do...

Basically, if you take this simple chunk of XML:

<?xml version="1.0"?>
<items>
<item id="cotbed">
<name>Cot-bed</name>
<uk price="200">
<urls>
<url title="Test title">http://tinyurl.com/ywuxc5</
url>
</urls>
</uk>
</item>
</items>

The 'url' isn't converted in to an object so you cannot access the
'title' parameter - it's just basically a string as can be seen by
this simple print_r output:

SimpleXMLElement Object
(
[item] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => cotbed
)

[name] => Cot-bed
[uk] => SimpleXMLElement Object
(
[@attributes] => Array
(
[price] => 200
)

[urls] => SimpleXMLElement Object
(
[url] => http://tinyurl.com/ywuxc5
)

)

)

)

Of course, if I made the url line look like this:

<url><title>Test title</title><link>http://tinyurl.com/ywuxc5</
link></url>

then it's naturally turned in to an object and gets the attribute:

[uk] => SimpleXMLElement Object
(
[@attributes] => Array
(
[price] => 200
)

[urls] => SimpleXMLElement Object
(
[url] => SimpleXMLElement Object
(
[title] => Test title
[link] => http://tinyurl.com/
ywuxc5
)

)

)

Am I wrong in thinking that the former format of url should get
converted to an object?

I'm calling simplexml_load_file with only one parameter, the file
name.

Cheers,

Andy

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация