Simplexml - how to use it with ["@attributes"]=>

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have just started reading about simplexml and made some test using
var_dump($xml); and when it used with a "normal" xml it's ok like this
and I can test it further:

object(SimpleXMLElement)#1 (1) {
  array(3) {
    object(SimpleXMLElement)#2 (3) {
      string(19) "Pride and Prejudice"
      string(11) "Jane Austen"
      string(32) "Jane Austen's most popular work."

but when I use it with a file I have made using phpmysql the code
looks like this:
object(SimpleXMLElement)#1 (1) {
  array(6) {
    object(SimpleXMLElement)#2 (1) {
      array(9) {
        string(34) "Dame & Herre & Handicap - Bemandet"
        string(29) "Nyhavn ved (Stor Skibs Anker)"
        string(4) "1051"
        string(1) "K"
        string(8) "handicap"
        string(67) "http://www.tinemuller.dk/new_wordpress/nyhavn-ved -
        string(9) "55.680433"
        string(9) "12.587767"
        string(1) "1"

I don't know how to handle  ["@attributes"]=> - can anyone help,


Re: Simplexml - how to use it with ["@attributes"]=>

tinem schreef:
Quoted text here. Click to load it


$xml = simplexml_load_string( $someXmlString );

echo $xml->marker[ 0 ][ "name" ];
echo $xml->marker[ 0 ][ "adresse" ];

echo $xml->marker[ 1 ][ "name" ];
echo $xml->marker[ 1 ][ "adresse" ];

Re: Simplexml - how to use it with ["@attributes"]=>

Thanks for trying to help.

I have this file now
and there are problems with the danish char and is $xmlStr =
file_get_contents the right way to get the info? Where can I learn
about how to change the output from the echo with for instance <br />
and other code?

I tried this for the danish char but it didn't work.
echo utf8_decode $xml->marker[0]["name"];

My code as it is now:

$xmlStr = file_get_contents('http://www.tinemuller.dk/toiletter /

$xml = simplexml_load_string($xmlStr);

echo $xml->marker[0]["name"];
echo $xml->marker[0]["adresse"];
echo $xml->marker[1]["name"];
echo $xml->marker[1]["adresse"];
echo $xml->marker[2]["name"];
echo $xml->marker[2]["adresse"];
echo $xml->marker[3]["name"];
echo $xml->marker[3]["adresse"];

Site Timeline