2

I have SimpleXMLElement Object looks like this

    SimpleXMLElement Object (
     [report-name] = SimpleXMLElement Object
         (
         [@attributes] = Array
             (
             [name] = Raport
             )

         )

     [date-range] = SimpleXMLElement Object
         (
         [@attributes] = Array
             (
             [date] = Jan 29, 2014
             )

         ) )

How can I get a 'date' value from this?

Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74
semafor
  • 81
  • 8
  • You can refer the manual for this. See this link [http://in1.php.net/simplexmlelement.attributes](http://in1.php.net/simplexmlelement.attributes) – user2936213 Jan 29 '14 at 10:45

2 Answers2

5

Source: PHP website, W3 Schools website

For basic usage of the simple XML object see the link to W3 schools.

To solve your problem with the hyphen see this example that comes directly from the PHP website:

$xml = simplexml_load_string($input);
$callback = $xml->{"callback-url"};
Marc van Nieuwenhuijzen
  • 1,637
  • 1
  • 14
  • 22
0

Hyphen (-) is the problem but you have children method this will help you.

For your better understanding

<?php

////xml which contains the hyphen
$string = <<<XML
<a>
 <x-y name="one" game="lonely">1</x-y>
</a>
XML;

//load XML object
$xml = simplexml_load_string($string);

//process each children
foreach($xml->children() as $a) 
{   
    //collect the attributes and process it
    foreach($a->attributes() as $b => $c) 
    {
        //name and value of attribute
        echo $b,'="',$c,"\"\n";

    }
}
Sundar
  • 4,580
  • 6
  • 35
  • 61