0
我需要得到一个属性:如何使用php获取xml属性?
<Info InstallPath="C:\Program Files\MyProg" Version="1.0" >
<Modules>
<parser.exe Launched="Off" />
<analyzer.exe Launched="On" />
</Modules>
</Info>
我写道:
echo $Parser = $xml->Info->Modules->parser.exe->attributes()->Launched;
但它不工作,因为 “parser.exe” 包含一个圆点
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';'
顺便说一句,这个问题是相当普遍的初学者,它是一样的破折号:http://stackoverflow.com/questions/9951753/php-simplexml-load-file-with-a-dash - 错误写出根元素的名称也是一个常见的错误。所有这些问题都得到了很好的解释,并且在http://php.net/simplexml.examples-basic(示例#2和#3)中进行了很好的说明。 – hakre