0

I need to get an attribute:

<Info  InstallPath="C:\Program Files\MyProg"  Version="1.0" >

    <Modules>
        <parser.exe Launched="Off" />
        <analyzer.exe Launched="On" />
    </Modules>

</Info>

I wrote:

echo $Parser = $xml->Info->Modules->parser.exe->attributes()->Launched;

But it does not work because "parser.exe" contains a dot

Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';'

hakre
  • 193,403
  • 52
  • 435
  • 836
Alex Lian
  • 47
  • 1
  • 1
  • 7
  • 1
    BTW the issue is quite common for starters, it is the same with a dash: http://stackoverflow.com/questions/9951753/php-simplexml-load-file-with-a-dash - And the mistake to write out the name of the root element is also a common mistake. All these issues are well explained and nicely demonstrated in: http://php.net/simplexml.examples-basic (Example #2 and #3). – hakre Oct 18 '13 at 16:52

1 Answers1

1

If <Info> is your root element then:

echo $xml->Modules->{'parser.exe'}->attributes()->Launched;

Because of the . character in your <parser.exe> element, you need to use the {} syntax to access the property.

In SimpleXML, the object ($xml) refers to the root element, so $xml->Info is not necessary.

MrCode
  • 63,975
  • 10
  • 90
  • 112