simpleXML中,将xml文件转成了一个对象,根节点就是这个对象,访问子节点就是对象的成员属性。有下面这个xml文档:
如何成功? 张三 39.8 成功人士应该有的特质 李四 42.8
$xml_obj=simplexml_load_file("books.xml"); $books=$xml_obj->book;$book=$books[0]; //这是第一本书,他是一个对象,他下面的子节点可以通过访问他的成员方法获取,但是他的属性,,,,,,$lang=$book["lang"];//获取他的属性,lang。以数组的方式访问,但是他不是一个对象吗? 我不明白的地方是这样的,访问节点属性的时候是以数组的方式去访问的,但是$book是一个对象啊!怎么变成数组了?
YXPHP6系统可以看做是一个模版平台,而且它又能独立工作. 而且YXPHP6系统也不需要数据库支持. 你可以开发自己的模板,也可以同步官方的模板后进行自己的二次开发,前提是您对YXPHP6要有一定的了解.YXPHP6不仅可以用作企业建站,甚至是blog,只要是您能想到的,YXPHP6几乎都可以胜任. 因为YXPHP6系统本身与模板之间可以说是独立运行的.也就是说,不管你做什么样的网站或者是应用,
回复讨论(解决方案)
http://www.php.net/manual/zh/class.arrayaccess.php
[book] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[lang] => 中文
)
[name] => 如何成功?
[author] => 张三
[price] => 39.8
)
摘录手册一段,留意红色部分:
-------------------------------------------------------
The SimpleXMLElement class
(No version information available, might only be in SVN)
简介
Represents an element in an XML document.
类摘要
SimpleXMLElement implements Traversable {
……
-----------------------------------------------------------------
Traversable 是SPL的一个类(目前手册并无具体介绍,但去 php.net 能发掘到)
再摘录一小段给你
-----------------------------------------------------------------------------
Traversable Interface Reference
[Zend engine classes]
Interface to detect a class is traversable using foreach. More...
Detailed Description
Interface to detect a class is traversable using foreach. //这就意味着是可迭代对象
Since:
PHP 5.0
Abstract base interface that cannot be implemented alone. Instead it must be implemented by either IteratorAggregate or Iterator.
Note:
Internal classes that implement this interface can be used in a foreach construct and do not need to implement IteratorAggregate or Iterator.
This is an engine internal interface which cannot be implemented in PHP scripts. Either IteratorAggregate or Iterator must be used instead.
Definition at line 509 of file spl.php.
--------------------------------------------------------------------------------
The documentation for this interface was generated from the following file:
spl.php
[book] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[lang] => 中文
)
[name] => 如何成功?
[author] => 张三
[price] => 39.8
)
[@attributes] => Array
这里的@是什么意思啊?我对正宗的数组var_dump没有出现这个@符号。
SimpleXMLElement 对象的属性数组
一般用遍历 attributes 方法返回的数组进行操作
你那样写也是可以的









