XML(Extensible Markup Language)即可扩展标记语言,它与HTML一样,都是SGML(Standard Generalized Markup Language,标准通用标记语言)。
- xml源文件
-
-
-
- 张映
- 男
- 28
-
-
- tank
- 男
- 28
-
-
-
-
-
- $doc = new DOMDocument();
- $doc->load('person.xml'); //读取xml文件
-
- $humans = $doc->getElementsByTagName( "humans" ); //取得humans标签的对象数组
-
- foreach( $humans as $human )
- {
- $names = $human->getElementsByTagName( "name" ); //取得name的标签的对象数组
- $name = $names->item(0)->nodeValue; //取得node中的值,如
-
- $sexs = $human->getElementsByTagName( "sex" );
- $sex = $sexs->item(0)->nodeValue;
-
- $olds = $human->getElementsByTagName( "old" );
- $old = $olds->item(0)->nodeValue;
-
- echo "$name - $sex - $old\n";
-
- }
- ?>
复制代码
|