Set of common php xml functions (more detailed)

Source: Internet
Author: User

1. DOM Functions

A. DOMDocument-> load ()
Purpose: load xml files.
Usage: DOMDocument-> load (string filename)
Parameter: filename, xml file;
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

B. DOMDocument-> loadXML ()
Purpose: load xml Code
Usage: DOMDocument-> loadXML (string source)
Parameter: source xml code;
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

C. DOMDocument-> getElementsByTagName_r ()
Purpose: search by Tag Name
Usage: DOMDocument-> getElementsByTagName_r (string name)
Parameter: name, label name;
Return Value: The New DOMNodeList object.

D. DOMDocument-> getElementById ()
Purpose: search by Tag Name
Usage: DOMDocument-> getElementById (string elementId)
Parameter: elementId, tag id;
Return Value: The New DOMNodeList object.

E. DOMDocument-> createElement_x_x ()
Purpose: Create a tag.
Usage: DOMDocument-> createElement_x_x (string name [, string value])
Parameter: name, label name, value, only;
Return Value: A New DOMElement object. The failure value is false.

F. DOMDocument-> createTextNode ()
Purpose: create a text node.
Usage: DOMDocument-> createTextNode (string content)
Parameter: content, content;
Return Value: A New DOMText object. The failure value is false.

H. DOMDocument-> createCDATASection ()
Purpose: Create a cdata Node
Usage: DOMDocument-> createCDATASection (string data)
Parameter: data, content;
Return Value: A New DOMCDATASection object. The failure value is false.

I. DOMDocument-> createAttribute ()
Purpose: Create tag attributes.
Usage: DOMDocument-> createAttribute (string name)
Parameter: name, attribute name;
Return Value: A New DOMAttr object. The failure value is false.

J. DOMDocument-> validate ()
Purpose: test the xml code.
Usage: DOMDocument-> validate ()
Parameter: None
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

K. DOMDocument-> save ()
Purpose: Save the xml code to the xml file.
Usage: DOMDocument-> save (string filename)
Parameter: filename, xml file;
Return: the xml character length is returned successfully. If the string fails, false is returned.

L. DOMDocument-> saveXML ()
Purpose: Save the xml code.
Usage: DOMDocument-> saveXML ([DOMNode node [, int options])
Parameter: node, DOMNode;
Return: xml is returned for success, and false is returned for failure.

M, DOMElement-> hasAttribute ()
Purpose: Check whether a property exists.
Usage: DOMElement-> hasAttribute (string name)
Parameter: name, attribute name;
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

N, DOMElement-> getAttribute ()
Purpose: Get the property value.
Usage: DOMElement-> getAttribute (string name)
Parameter: name, attribute name;
Return: the property value is returned successfully. If the property value is returned, null is returned.

O, DOMElement-> getAttribute ()
Purpose: Get the property value.
Usage: DOMElement-> getAttribute (string name)
Parameter: name, attribute name;
Return: the property value is returned successfully. If the property value is returned, null is returned.

P, DOMElement-> setAttribute ()
Purpose: set the attribute value.
Usage: DOMElement-> setAttribute (string name, string value)
Parameter: name, attribute name; value, attribute value
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

Q, DOMNode-> appendChild ()
Purpose: link the child node to the parent node.
Usage: DOMNode-> appendChild (DOMNode newnode)
Parameter: newnode, new node;
Return: the node is returned successfully. If the node fails, null is returned.

R, DOMNode-> hasAttributes ()
Purpose: Check whether attributes exist.
Usage: DOMNode-> hasAttributes ()
Parameter: None
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

S, DOMNode-> hasChildNodes ()
Purpose: Check whether subnodes exist.
Usage: DOMNode-> hasChildNodes ()
Parameter: None
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

T, DOMNode-> insertBefore ()
Purpose: insert the child node into the dom tree, which is located before a node.
Usage: DOMNode-> insertBefore (DOMNode newnode [, DOMNode refnode])
Parameter: newnode, new node; refnode, refer to node
Return: A new node is returned successfully. If the node fails, a blank value is returned.

U, DOMNode-> removeChild ()
Purpose: delete a subnode.
Usage: DOMNode-> removeChild (DOMNode oldnode)
Parameter: oldnode, subnode;
Return: The child node is returned successfully. If the child node fails, null is returned.

V, DOMNode-> replaceChild ()
Purpose: update a subnode.
Usage: DOMNode-> replaceChild (DOMNode newnode, DOMNode oldnode)
Parameter: newnode, new node, oldnode, old node
Return: The oldnode is returned successfully. If the node fails, null is returned.

--------- DOMNode attribute -------------

A. DOMNode-> nodeType
Purpose: Obtain the node type.

B. DOMNode-> nodeName
Purpose: Get the node name

C. DOMNode-> nodeValue
Purpose: Get node content

D. DOMNode-> textContent
Purpose: Get node content

E. DOMNode-> parentNode
Purpose: Obtain the parent node of a node.

F. DOMNode-> childNodes
Purpose: Obtain node subnodes.

G, DOMNode-> firstChild
Purpose: obtain the first subnode of a node.

H. DOMNode-> lastChild
Purpose: Obtain the last subnode of a node.

2. XMLReader

A. XMLReader: XML
Purpose: load an xml string.
Usage: XMLReader: xml (string source [, string encoding [, int options])
Parameter: source, xml string; encoding, document encoding or NULL
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

B. XMLReader: open
Purpose: load an xml file.
Usage: XMLReader: open (string url [, string encoding [, int options])
Parameter: url, link to xml; encoding, document encoding or NULL
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

C. XMLReader: read
Purpose: Read xml to forward the parser to the next tag.
Usage: XMLReader: read (), traversing the entire document in the while LOOP
Parameter: NULL
Return: if the operation succeeds, TRUE is returned. If the operation fails, FALSE is returned.

D. XMLReader: getAttribute
Purpose: Get attributes
Usage: XMLReader: getAttribute (string name)
Parameter: name, attribute name
Return: if the operation succeeds, the property value is returned. If the operation fails, FALSE is returned.

E. XMLReader: isValid
Purpose: Check whether xml is legal
Usage: XMLReader: isValid ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

F. XMLReader: moveToAttribute
Purpose: Move the focus to the attribute.
Usage: XMLReader: moveToAttribute (string name)
Parameter: name, attribute name
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

G, XMLReader: moveToFirstAttribute
Purpose: Move the focus to the first attribute.
Usage: XMLReader: moveToFirstAttribute ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

H. XMLReader: moveToNextAttribute
Purpose: Move the focus to the next attribute.
Usage: XMLReader: moveToNextAttribute ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

I. XMLReader: moveToElement
Purpose: Move the focus to the current attribute of the parent node.
Usage: XMLReader: moveToElement ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

J. XMLReader: close
Purpose: Disable xml input.
Usage: XMLReader: close ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

-------- Constant ---------

XMLReader: NONE = 0;
XMLReader: ELEMENT = 1;
XMLReader: ATTRIBUTE = 2;
XMLReader: TEXT = 3;
XMLReader: CDATA = 4;
XMLReader: ENTITY_REF = 5;
XMLReader: ENTITY = 6;
XMLReader: PI = 7;
XMLReader: COMMENT = 8;
XMLReader: DOC = 9;
XMLReader: DOC_TYPE = 10;
XMLReader: DOC_FRAGMENT = 11;
XMLReader: NOTATION = 12;
XMLReader: WHITESPACE = 13;
XMLReader: SIGNIFICANT_WHITESPACE = 14;
XMLReader: END_ELEMENT = 15;
XMLReader: END_ENTITY = 16;
XMLReader: XML_DECLARATION = 17;
XMLReader: LOADDTD = 1;
XMLReader: DEFAULTATTRS = 2;
XMLReader: VALIDATE = 3;
XMLReader: SUBST_ENTITIES = 4;

-------- Properties -----------

A. XMLReader-> attributeCount;
Role: number of attributes

B. XMLReader-> baseURI;
Role: node url

C. XMLReader-> depth;
Role: number of layers of the node tree

D. XMLReader-> hasAttributes;
Purpose: Check whether any attribute exists.

E. XMLReader-> hasValue;
Role: whether there is a value

F. XMLReader-> isEmptyElement;
Purpose: whether the tag is empty.

G, XMLReader-> localName;
Role: label description

H. XMLReader-> name;
Role: Tag Name

I. XMLReader-> nodeType;
Role: Node Type

J. XMLReader-> value;
Purpose: content of the node text

3. XMLWriter

A. XMLWriter: openURI
Purpose: Create an XMLWriter from the url output code.
Usage: XMLWriter: openURI (string uri)
Parameter: url xml address
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

B. XMLWriter: setIndentString
Purpose: Set indentation characters.
Usage: XMLWriter: setIndentString (string indentString)
Parameter: indentString indent character
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

C. XMLWriter: setIndent
Purpose: set the indent switch.
Usage: XMLWriter: setIndent (bool indent)
Parameter: indent or not
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

D. XMLWriter: startDocument
Purpose: set the document start tag.
Usage: XMLWriter: startDocument ([string version [, string encoding [, string standalone])
Parameter: version, version, encoding, encoding, standalone, independent
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

E. XMLWriter: endDocument
Purpose: set the document end tag.
Usage: XMLWriter: endDocument ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

F. XMLWriter: startDTD
Purpose: set the dtd start tag.
Usage: XMLWriter: startDTD (string qualifiedName [, string publicId [, string systemId])
Parameter: qualifiedName, name; publicId, piublic; systemId, system
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

G, XMLWriter: endDTD
Purpose: set the dtd end tag.
Usage: XMLWriter: endDTD ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

H. XMLWriter: startElement
Purpose: set the start tag.
Usage: XMLWriter: startElement (string name)
Parameter: name, label name
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

I. XMLWriter: endElement
Purpose: set the end tag.
Usage: XMLWriter: endElement ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

J. XMLWriter: startCData
Purpose: set the start tag.
Usage: XMLWriter: startCData ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

K. XMLWriter: endCData
Purpose: set the end tag.
Usage: XMLWriter: endCData ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

L. XMLWriter: writeAttribute
Purpose: Write tag attributes.
Usage: XMLWriter: writeAttribute (string name, string value)
Parameter: name, attribute name; value, attribute value
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

M, XMLWriter: writeElement
Purpose: Write tag attributes.
Usage: XMLWriter: writeElement (resource xmlwriter, string name, string content)
Parameter: xmlwriter, xml resource; name, Tag name; value, text value
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

N, XMLWriter: writeCData
Purpose: Write tag attributes.
Usage: XMLWriter: writeCData (resource xmlwriter, string content)
Parameter: xmlwriter, xml resource; value, text value
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

O, XMLWriter: text
Purpose: write text
Usage: XMLWriter: text (string content)
Parameter: content, text value
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

P, XMLWriter: flush
Purpose: Clear Cache
Usage: XMLWriter: flush ()
Parameter: None
Return: if the operation succeeds, true is returned. If the operation fails, FALSE is returned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.