Các chức năng của PHP SimpleXML
Giới thiệu PHP SimpleXML
SimpleXML là một phần mở rộng cho phép chúng ta dễ dàng thao tác và lấy dữ liệu XML.
SimpleXML cung cấp một cách dễ dàng để lấy tên, thuộc tính và nội dung văn bản của phần tử nếu bạn biết cấu trúc hoặc bố cục của tài liệu XML.
SimpleXML biến một tài liệu XML thành một cấu trúc dữ liệu mà bạn có thể lặp lại giống như một tập hợp các mảng và đối tượng.
Cài đặt
Từ PHP 5, các hàm SimpleXML là một phần của lõi PHP. Không cần cài đặt để sử dụng các chức năng này.
Các chức năng của PHP SimpleXML
Function | Description |
---|---|
__construct() | Creates a new SimpleXMLElement object |
__toString() | Returns the string content of an element |
addAttribute() | Appends an attribute to the SimpleXML element |
addChild() | Appends a child element the SimpleXML element |
asXML() | Returns a well-formed XML string (XML version 1.0) from a SimpleXML object |
attributes() | Returns the attributes/values of an element |
children() | Returns the children of a specified node |
count() | Counts the children of a specified node |
getDocNamespaces() | Returns the namespaces declared in document |
getName() | Returns the name of an element |
getNamespaces() | Returns the namespaces used in document |
registerXPathNamespace() | Creates a namespace context for the next XPath query |
saveXML() | Alias of asXML() |
simplexml_import_dom() | Returns a SimpleXMLElement object from a DOM node |
simplexml_load_file() | Converts an XML document to an object |
simplexml_load_string() | Converts an XML string to an object |
xpath() | Runs an XPath query on XML data |
Các chức năng lặp lại PHP SimpleXML
Function | Description |
---|---|
current() | Returns the current element |
getChildren() | Returns the child elements of the current element |
hasChildren() | Checks whether the current element has children |
key() | Returns the XML tag name of the current element |
next() | Moves to the next element |
rewind() | Rewinds to the first element |
valid() | Checks whether the current element is valid |