PHP如何实现一个完整的XML简单操作类实例?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1684个文字,预计阅读时间需要7分钟。
本例展示了如何使用PHP封装XML的简单操作。以下是一个XML处理类的示例:
php
class XML_Dom{ protected $xml;
public function __construct($xmlContent) { $this->xml=new DOMDocument(); $this->xml->loadXML($xmlContent); }
public function getElement($path) { $xpath=new DOMXPath($this->xml); return $xpath->query($path)->item(0); }
public function getAttribute($element, $attributeName) { return $element->getAttribute($attributeName); }
public function setText($element, $text) { $element->textContent=$text; }}?>
本文实例讲述了PHP封装的XML简单操作类。
本文共计1684个文字,预计阅读时间需要7分钟。
本例展示了如何使用PHP封装XML的简单操作。以下是一个XML处理类的示例:
php
class XML_Dom{ protected $xml;
public function __construct($xmlContent) { $this->xml=new DOMDocument(); $this->xml->loadXML($xmlContent); }
public function getElement($path) { $xpath=new DOMXPath($this->xml); return $xpath->query($path)->item(0); }
public function getAttribute($element, $attributeName) { return $element->getAttribute($attributeName); }
public function setText($element, $text) { $element->textContent=$text; }}?>
本文实例讲述了PHP封装的XML简单操作类。

