A collection of commonly used functions in PHP XML (more detailed) _php tips

Source: Internet
Author: User
Tags cdata flush tag name

1. DOM function

A, Domdocument->load ()
Function: Load XML file
Usage: domdocument->load (string filename)
Parameters: Filename,xml file;
Return: Returns TRUE if successful and FALSE if failed.

B, Domdocument->loadxml ()
function: Load XML code
Usage: Domdocument->loadxml (string source)
Parameters: source XML code;
Return: Returns TRUE if successful and FALSE if failed.

C, Domdocument->getelementsbytagname_r ()
Function: Find by tag name
Usage: Domdocument->getelementsbytagname_r (string name)
Parameters: Name, label names;
Returns: The new Domnodelist object.

D, Domdocument->getelementbyid ()
Function: Find by tag name
Usage: Domdocument->getelementbyid (string elementid)
Parameters: ElementID, tag ID;
Returns: The new Domnodelist object.

E, domdocument->createelement_x_x ()
Function: Create a label
Usage: domdocument->createelement_x_x (string name [, String value])
Argument: Name, tag name, value, only;
Returns: The new DomElement object failed to false.

F, Domdocument->createtextnode ()
Function: Create a text node
Usage: Domdocument->createtextnode (string content)
Parameters: content, contents;
Returns: The new Domtext object failed to false.

H, Domdocument->createcdatasection ()
Function: Create a CDATA node
Usage: domdocument->createcdatasection (string data)
Parameters: data, content;
Returns: The new Domcdatasection object failed to false.

I, Domdocument->createattribute ()
Function: Create label properties
Usage: Domdocument->createattribute (string name)
Parameters: Name, attribute names;
Returns: The new Domattr object failed to false.

J, Domdocument->validate ()
Function: Validate XML code
Usage: domdocument->validate ()
Parameters: None
Return: Returns TRUE if successful and FALSE if failed.

K, Domdocument->save ()
Function: Save XML code to XML file
Usage: domdocument->save (string filename)
Parameters: Filename,xml file;
return: The XML character length was successfully returned and failed to return false.

L, Domdocument->savexml ()
Function: Save XML code
Usage: domdocument->savexml ([Domnode node [, int options]])
Parameters: Node,domnode;
Return: Successfully returned XML, failure returns false.

M, Domelement->hasattribute ()
Function: Detect whether a property exists
Usage: Domelement->hasattribute (string name)
Parameters: Name, attribute names;
Return: Returns TRUE if successful and FALSE if failed.

N, Domelement->getattribute ()
Function: Get property value
Usage: Domelement->getattribute (string name)
Parameters: Name, attribute names;
Return: Property value returned successfully, failure returned empty.

O, Domelement->getattribute ()
Function: Get property value
Usage: Domelement->getattribute (string name)
Parameters: Name, attribute names;
Return: Property value returned successfully, failure returned empty.

P, Domelement->setattribute ()
Function: Set property value
Usage: Domelement->setattribute (string name, String value)
Parameters: Name, attribute name; value, property value
Return: Returns TRUE if successful and FALSE if failed.

Q, Domnode->appendchild ()
Role: Link child nodes to parent node
Usage: domnode->appendchild (Domnode newnode)
Parameters: NewNode, new node;
Return: The new node was successfully returned and the failure returned empty.

R, Domnode->hasattributes ()
Function: Verify that there are attributes
Usage: domnode->hasattributes ()
Parameters: None
Return: Returns TRUE if successful and FALSE if failed.

S, Domnode->haschildnodes ()
Action: Detects whether there are child nodes
Usage: domnode->haschildnodes ()
Parameters: None
Return: Returns TRUE if successful and FALSE if failed.

T, Domnode->insertbefore ()
Role: The node inserted into the DOM tree, position in front of a node
Usage: Domnode->insertbefore (Domnode newnode [, Domnode Refnode])
Parameters: NewNode, new Node;refnode, referencing node
Return: The new node was successfully returned and the failure returned empty.

U, Domnode->removechild ()
function: Delete child nodes
Usage: domnode->removechild (domnode OldNode)
Parameters: OldNode, child nodes;
Return: The child node was successfully returned and the failure returned empty.

V, Domnode->replacechild ()
Role: Updating child nodes
Usage: domnode->replacechild (domnode newnode, Domnode OldNode)
Parameters: NewNode, new Node;oldnode, old node
Return: Successfully returned OldNode, failed to return empty.

————————-Domnode Property ———————————— –

A, Domnode->nodetype
Function: Get node type

B, Domnode->nodename
Function: Get node name

C, Domnode->nodevalue
Function: Get node content

D, Domnode->textcontent
Function: Get node content

E, Domnode->parentnode
Function: Get node parent node

F, Domnode->childnodes
function: Get nodes of node ideas

G, Domnode->firstchild
Function: Gets the first child node of a node

H, Domnode->lastchild
Function: Gets the last child node of a node

2, XMLReader

A, Xmlreader::xml
Function: Load XML string
Usage: xmlreader::xml (string source [, string encoding [, int options]])
Parameters: Source,xml string;encoding,document encoding or NULL
Return: Returns TRUE if successful and FALSE if failed.

B, Xmlreader::open
Function: Load XML file
Usage: xmlreader::open (string URL [, string encoding [, int options]])
Parameters: URL, link to XML; encoding,document encoding or NULL
Return: Returns TRUE if successful and FALSE if failed.

C, Xmlreader::read
Function: Read XML to move the parser forward to the next tag
Usage: xmlreader::read (), traversing the entire document in the while loop
Parameters: NULL
Return: Returns TRUE if successful and FALSE if failed.

D, Xmlreader::getattribute
Function: Get Properties
Usage: Xmlreader::getattribute (string name)
Parameters: Name, attribute names
Returns: Returns the property value if successful, and returns FALSE if it fails.

E, Xmlreader::isvalid
Role: Verify that the XML is legitimate
Usage: xmlreader::isvalid ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

F, Xmlreader::movetoattribute
Function: Move focus to the attribute you refer to
Usage: Xmlreader::movetoattribute (string name)
Parameters: Name, attribute names
Return: Returns True if successful and FALSE if failed.

G, Xmlreader::movetofirstattribute
Function: Move focus to first attribute
Usage: Xmlreader::movetofirstattribute ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

H, Xmlreader::movetonextattribute
Function: Move focus to the next property
Usage: Xmlreader::movetonextattribute ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

I, xmlreader::movetoelement
Function: Move focus to the parent node's current properties
Usage: xmlreader::movetoelement ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

J, Xmlreader::close
Function: Turn off XML input
Usage: xmlreader::close ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

———————-Constant ———————— –

Xmlreader::none = 0;
Xmlreader::element = 1;
Xmlreader::attribute = 2;
Xmlreader::text = 3;
Xmlreader::cdata = 4;
Xmlreader::entity_ref = 5;
Xmlreader::entity = 6;
XMLReader::P i = 7;
Xmlreader::comment = 8;
XMLReader::D oc = 9;
XMLReader::D oc_type = 10;
XMLReader::D oc_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::D efaultattrs = 2;
Xmlreader::validate = 3;
Xmlreader::subst_entities = 4;

———————— Property —————————— –

A, xmlreader->attributecount;
Role: Number of attributes

b, Xmlreader->baseuri;
Function: URL of node

C, xmlreader->depth;
Function: Number of layers of node tree

D, Xmlreader->hasattributes;
Function: Detect if there are attributes

E, Xmlreader->hasvalue;
Function: Whether there is a value

F, xmlreader->isemptyelement;
Function: Whether it is an empty label

G, Xmlreader->localname;
Function: Label Internal Ming

h, Xmlreader->name;
Role: Label name

I, Xmlreader->nodetype;
Function: Node type

J, Xmlreader->value;
Function: Node text content

3, XMLWriter

A, Xmlwriter::openuri
Role: Create a new XmlWriter from the URL output code
Usage: Xmlwriter::openuri (string uri)
Parameters: URL XML address
Return: Returns True if successful and FALSE if failed.

B, xmlwriter::setindentstring
Function: Set indent characters
Usage: xmlwriter::setindentstring (string indentstring)
Parameters: Indentstring Indent characters
Return: Returns True if successful and FALSE if failed.

C, xmlwriter::setindent
Function: Set indent switch
Usage: xmlwriter::setindent (bool indent)
Parameters: Indent indentation or not
Return: Returns True if successful and FALSE if failed.

D, Xmlwriter::startdocument
Function: Set document Start label
Usage: xmlwriter::startdocument ([String version [, string encoding [, string standalone]]])
Parameters: version, edition; encoding, coding; standalone, Independent
Return: Returns True if successful and FALSE if failed.

E, xmlwriter::enddocument
Function: Set end of document tag
Usage: xmlwriter::enddocument ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

F, Xmlwriter::startdtd
Function: Set DTD start tag
Usage: XMLWRITER::STARTDTD (string QualifiedName [, String publicid [, String SystemID]])
Parameters: QualifiedName, name; Publicid,piublic;systemid,system
Return: Returns True if successful and FALSE if failed.

G, XMLWRITER::ENDDTD
Role: Set DTD end tag
Usage: XMLWRITER::ENDDTD ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

H, Xmlwriter::startelement
Function: Set start tag
Usage: xmlwriter::startelement (string name)
Parameters: Name, label names
Return: Returns True if successful and FALSE if failed.

I, xmlwriter::endelement
Function: Set end tag
Usage: xmlwriter::endelement ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

J, Xmlwriter::startcdata
Function: Set start tag
Usage: xmlwriter::startcdata ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

K, Xmlwriter::endcdata
Function: Set end tag
Usage: xmlwriter::endcdata ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

L, Xmlwriter::writeattribute
Function: Write Tag Properties
Usage: Xmlwriter::writeattribute (string name, String value)
Parameters: Name, attribute name; value, property value
Return: Returns True if successful and FALSE if failed.

M, xmlwriter::writeelement
Function: Write Tag Properties
Usage: xmlwriter::writeelement (Resource XMLWriter, string name, string content)
Parameters: Xmlwriter,xml resource; name, tag name; value, text value
Return: Returns True if successful and FALSE if failed.

N, Xmlwriter::writecdata
Function: Write Tag Properties
Usage: Xmlwriter::writecdata (resource XMLWriter, string content)
Parameters: Xmlwriter,xml resource; value, text value
Return: Returns True if successful and FALSE if failed.

O, Xmlwriter::text
Function: Write text
Usage: Xmlwriter::text (string content)
Parameters: Content, text value
Return: Returns True if successful and FALSE if failed.

P, Xmlwriter::flush
Function: Empty cache
Usage: Xmlwriter::flush ()
Parameters: None
Return: Returns True if successful and FALSE if failed.

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.