Home  >  Article  >  Backend Development  >  A collection of commonly used functions in php xml (more detailed)_PHP tutorial

A collection of commonly used functions in php xml (more detailed)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:08:53794browse

1、DOM 函数

a、DOMDocument->load()
作用:加载xml文件
用法:DOMDocument->load( string filename )
参数:filename,xml文件;
返回:如果成功则返回 TRUE,失败则返回 FALSE。

b、DOMDocument->loadXML()
作用:加载xml代码
用法:DOMDocument->loadXML( string source )
参数:source xml代码;
返回:如果成功则返回 TRUE,失败则返回 FALSE。

c、DOMDocument->getElementsByTagName_r()
作用:按标签名查找
用法:DOMDocument->getElementsByTagName_r(string name)
参数:name,标签名称;
返回:新的 DOMNodeList 对象 。

d、DOMDocument->getElementById()
作用:按标签名查找
用法:DOMDocument->getElementById(string elementId )
参数:elementId ,标签id;
返回:新的 DOMNodeList 对象 。

e、DOMDocument->createElement_x_x()
作用:创建标签
用法:DOMDocument->createElement_x_x(string name [, string value] )
参数:name,标签名称,value,只;
返回:新的 DOMElement 对象,失败为false 。

f、DOMDocument->createTextNode()
作用:创建文本节点
用法:DOMDocument->createTextNode(string content )
参数:content,内容;
返回:新的 DOMText 对象,失败为false 。

h、DOMDocument->createCDATASection()
作用:创建cdata节点
用法:DOMDocument->createCDATASection( string data )
参数:data,内容;
返回:新的 DOMCDATASection 对象,失败为false 。

i、DOMDocument->createAttribute()
作用:创建标签属性
用法:DOMDocument->createAttribute(string name)
参数:name,属性名称;
返回:新的 DOMAttr 对象,失败为false 。

j、DOMDocument->validate()
作用:检验xml代码
用法:DOMDocument->validate()
参数:无
返回:如果成功则返回 TRUE,失败则返回 FALSE。

k、DOMDocument->save()
作用:保存xml代码到xml文件
用法:DOMDocument->save(string filename )
参数:filename,xml文件;
返回:成功返回xml字符长度,失败返回false。

l、DOMDocument->saveXML()
作用:保存xml代码
用法:DOMDocument->saveXML( [DOMNode node [, int options]] )
参数:node,DOMNode;
返回:成功返回xml,失败返回false。

m、DOMElement->hasAttribute()
作用:检测属性是否存在
用法:DOMElement->hasAttribute(string name)
参数:name,属性名称;
返回:如果成功则返回 TRUE,失败则返回 FALSE。

n、DOMElement->getAttribute()
作用:获取属性值
用法:DOMElement->getAttribute(string name)
参数:name,属性名称;
返回:成功返回属性值,失败返回空。

o、DOMElement->getAttribute()
作用:获取属性值
用法:DOMElement->getAttribute(string name)
参数:name,属性名称;
返回:成功返回属性值,失败返回空。

p、DOMElement->setAttribute()
作用:设置属性值
用法:DOMElement->setAttribute(string name, string value )
参数:name,属性名称;value,属性值
返回:如果成功则返回 TRUE,失败则返回 FALSE。

q、DOMNode->appendChild()
作用:将子节点链接到父节点上
用法:DOMNode->appendChild(DOMNode newnode )
参数:newnode,新节点;
返回:成功返回新节点,失败返回空。

r、DOMNode->hasAttributes()
作用:检验是否有属性
用法:DOMNode->hasAttributes( )
参数:无
返回:如果成功则返回 TRUE,失败则返回 FALSE。

s、DOMNode->hasChildNodes()
作用:检测是否有子节点
用法:DOMNode->hasChildNodes()
参数:无
返回:如果成功则返回 TRUE,失败则返回 FALSE。

t、DOMNode->insertBefore()
作用:把子节点插入dom树,位置在某节点前
用法:DOMNode->insertBefore(DOMNode newnode [, DOMNode refnode] )
参数:newnode,新node;refnode,参照node
返回:成功返回新node,失败返回空。

u、DOMNode->removeChild()
作用:删除子节点
用法:DOMNode->removeChild(DOMNode oldnode )
参数:oldnode,子节点;
返回:成功返回子节点,失败返回空。

v、DOMNode->replaceChild()
作用:更新子节点
用法:DOMNode->replaceChild(DOMNode newnode, DOMNode oldnode )
参数:newnode,新node;oldnode,老的node
返回:成功返回oldnode,失败返回空。

————————-DOMNode 属性————————————–

a、DOMNode->nodeType
作用:获取节点类型

b、DOMNode->nodeName
作用:获取节点名称

c、DOMNode->nodeValue
作用:获取节点内容

d、DOMNode->textContent
作用:获取节点内容

e、DOMNode->parentNode
作用:获取节点父节点

f、DOMNode->childNodes
作用:获取节点子节点

g、DOMNode->firstChild
作用:获取节点第一个子节点

h、DOMNode->lastChild
作用:获取节点最后一个子节点

2、XMLReader

a、XMLReader::XML
作用:载入 xml 字符串
用法:XMLReader::xml(string source [, string encoding [, int options]] )
参数:source,xml string;encoding,document encoding or NULL
返回:如果成功则返回 TRUE,失败则返回 FALSE。

b、XMLReader::open
作用:载入xml文件
用法:XMLReader::open(string url [, string encoding [, int options]] )
参数:url,连接到xml的链接;encoding,document encoding or NULL
返回:如果成功则返回 TRUE,失败则返回 FALSE。

c、XMLReader::read
作用:读取 xml,使解析器前进到下一个标记
用法:XMLReader::read(),在 while 循环中遍历整个文档
参数:NULL
返回:如果成功则返回 TRUE,失败则返回 FALSE。

d、XMLReader::getAttribute
作用:获取属性
用法:XMLReader::getAttribute(string name)
参数:name,属性名称
返回:如果成功则返回 属性值,失败则返回 FALSE。

e、XMLReader::isValid
作用:检验xml是否合法
用法:XMLReader::isValid()
参数:无
返回:如果成功则返回 true,失败则返回 FALSE。

f、XMLReader::moveToAttribute
作用:移动焦点到所指的属性上
用法:XMLReader::moveToAttribute(string name)
参数:name,属性名称
返回:如果成功则返回 true,失败则返回 FALSE。

g、XMLReader::moveToFirstAttribute
作用:移动焦点到第一个属性上
用法:XMLReader::moveToFirstAttribute()
参数:无
返回:如果成功则返回 true,失败则返回 FALSE。

h、XMLReader::moveToNextAttribute
作用:移动焦点到下一个属性上
用法:XMLReader::moveToNextAttribute()
参数:无
返回:如果成功则返回 true,失败则返回 FALSE。

i、XMLReader::moveToElement
作用:移动焦点到父节点当前属性上
用法:XMLReader::moveToElement()
参数:无
返回:如果成功则返回 true,失败则返回 FALSE。

j、XMLReader::close
作用:关闭xml输入
用法:XMLReader::close()
参数:无
返回:如果成功则返回 true,失败则返回 FALSE。

———————-常量————————–

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 ;

————————属性——————————–

a、XMLReader->attributeCount ;
作用:属性数量

b、XMLReader->baseURI ;
作用:节点的url

c、XMLReader->depth ;
作用:节点树的层数

d, XMLReader->hasAttributes;
Function: Detect whether there are attributes

e, XMLReader->hasValue;
Function: whether there is a value

f, XMLReader->isEmptyElement;
Function: Whether it is an empty tag

g, XMLReader->localName;
Function: tag internally clear

h, XMLReader->name;
Function: tag name

i, XMLReader->nodeType;
Function: Node type

j, XMLReader->value;
Function: Node text content

3. XMLWriter

a. XMLWriter::openURI
Function: Create a new XMLWriter from the url output code
Usage: XMLWriter::openURI(string uri)
Parameter: url xml address
Return: Return true if successful, return FALSE if failed.

b, XMLWriter::setIndentString
Function: Set the indent character
Usage: XMLWriter::setIndentString(string indentString)
Parameter: indentString indent character
Return : Returns true if successful, FALSE if failed.

c, XMLWriter::setIndent
Function: Set the indent switch
Usage: XMLWriter::setIndent(bool indent)
Parameter: indent indent or not
Returns: true if successful, FALSE if failed.

d, XMLWriter::startDocument
Function: Set the document start tag
Usage: XMLWriter::startDocument([string version [, string encoding [, string standalone]]] )
Parameters: version, version; encoding, encoding; standalone, independent
Return: true if successful, FALSE if failed.

e, XMLWriter::endDocument
Function: Set the document end tag
Usage: XMLWriter::endDocument()
Parameters: None
Return: Return if successful true, or FALSE on failure.

f, XMLWriter::startDTD
Function: Set the dtd start tag
Usage: XMLWriter::startDTD( string qualifiedName [, string publicId [, string systemId]] )
Parameters: qualifiedName, name; publicId, piublic; systemId, system
Return: true if successful, FALSE if failed.

g, XMLWriter::endDTD
Function: Set the dtd end tag
Usage: XMLWriter::endDTD()
Parameters: None
Return: Return if successful true, or FALSE on failure.

h, XMLWriter::startElement
Function: Set the start tag
Usage: XMLWriter::startElement(string name)
Parameters: name, tag name
Return: Returns true if successful, FALSE if failed.

i, XMLWriter::endElement
Function: Set the end tag
Usage: XMLWriter::endElement()
Parameters: None
Return: Return true if successful , returns FALSE on failure.

j, XMLWriter::startCData
Function: Set the start tag
Usage: XMLWriter::startCData()
Parameters: None
Return: Return true if successful , returns FALSE on failure.

k, XMLWriter::endCData
Function: Set the end tag
Usage: XMLWriter::endCData ()
Parameters: None
Return: Return true if successful , returns FALSE on failure.

l, XMLWriter::writeAttribute
Function: Write tag attributes
Usage: XMLWriter::writeAttribute (string name, string value)
Parameters: name, attribute name; value , attribute value
returns: true if successful, FALSE if failed.

m, XMLWriter::writeElement
Function: Write tag attributes
Usage: XMLWriter::writeElement (resource xmlwriter, string name, string content)
Parameters: xmlwriter, xml Resource; name, tag name; value, text value
Return: true if successful, FALSE if failed.

n, XMLWriter::writeCData
Function: write tag attributes
Usage: XMLWriter::writeCData (resource xmlwriter, string content)
Parameters: xmlwriter, xml resource; value , text value
Returns: true if successful, FALSE if failed.

o, XMLWriter::text
Function: write text
Usage: XMLWriter::text (string content)
Parameter: content, text value
Return: if Returns true on success and FALSE on failure.

p, XMLWriter::flush
Function: Clear cache
Usage: XMLWriter::flush ()
Parameters: None
Return: Return true if successful, Returns FALSE on failure.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327423.htmlTechArticle1. DOM function a. DOMDocument-load() Function: Load xml file Usage: DOMDocument-load( string filename ) Parameters: filename, xml file; Return: TRUE if successful, if failed...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn