Home php教程 php手册 php xml常用函数的集合

php xml常用函数的集合

Jun 13, 2016 am 11:33 AM
dom php xml effect function load Commonly used document usage of gather

   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 ;

  作用:检测是否有属性

  e、XMLReader->hasValue ;

  作用:是否有值

  f、XMLReader->isEmptyElement ;

  作用:是否是空标签

  g、XMLReader->localName ;

  作用:标签内部明

  h、XMLReader->name ;

  作用:标签名

  i、XMLReader->nodeType ;

  作用:节点类型

  j、XMLReader->value ;

  作用:节点文本内容

  3、XMLWriter

  a、XMLWriter::openURI

  作用:从url输出代码创建新的XMLWriter

  用法:XMLWriter::openURI(string uri )

  参数:url xml地址

  返回:如果成功则返回 true,失败则返回 FALSE。

  b、XMLWriter::setIndentString

  作用:设置缩进字符

  用法:XMLWriter::setIndentString(string indentString )

  参数:indentString 缩进字符

  返回:如果成功则返回 true,失败则返回 FALSE。

  c、XMLWriter::setIndent

  作用:设置缩进开关

  用法:XMLWriter::setIndent(bool indent )

  参数:indent 缩进与否

  返回:如果成功则返回 true,失败则返回 FALSE。

  d、XMLWriter::startDocument

  作用:设置文档开始标签

  用法:XMLWriter::startDocument( [string version [, string encoding [, string standalone]]] )

  参数:version,版本;encoding,编码;standalone,独立的

  返回:如果成功则返回 true,失败则返回 FALSE。

  e、XMLWriter::endDocument

  作用:设置文档结束标签

  用法:XMLWriter::endDocument( )

  参数:无

  返回:如果成功则返回 true,失败则返回 FALSE。

  f、XMLWriter::startDTD

  作用:设置dtd开始标签

  用法:XMLWriter::startDTD( string qualifiedName [, string publicId [, string systemId]] )

  参数:qualifiedName,名称;publicId,piublic;systemId,system

  返回:如果成功则返回 true,失败则返回 FALSE。

  g、XMLWriter::endDTD

  作用:设置dtd结束标签

  用法:XMLWriter::endDTD()

  参数:无

  返回:如果成功则返回 true,失败则返回 FALSE。

  h、XMLWriter::startElement

  作用:设置开始标签

  用法:XMLWriter::startElement(string name )

  参数:name,标签名称

  返回:如果成功则返回 true,失败则返回 FALSE。

  i、XMLWriter::endElement

  作用:设置结束标签

  用法:XMLWriter::endElement()

  参数:无

  返回:如果成功则返回 true,失败则返回 FALSE。

  j、XMLWriter::startCData

  作用:设置开始标签

  用法:XMLWriter::startCData()

  参数:无

  返回:如果成功则返回 true,失败则返回 FALSE。

  k、XMLWriter::endCData

  作用:设置结束标签

  用法:XMLWriter::endCData ()

  参数:无

  返回:如果成功则返回 true,失败则返回 FALSE。

  l、XMLWriter::writeAttribute

  作用:写标签属性

  用法:XMLWriter::writeAttribute (string name, string value )

  参数:name,属性名称;value,属性值

  返回:如果成功则返回 true,失败则返回 FALSE。

  m、XMLWriter::writeElement

  作用:写标签属性

  用法:XMLWriter::writeElement (resource xmlwriter, string name, string content )

  参数:xmlwriter,xml资源;name,标签名称;value,文本值

  返回:如果成功则返回 true,失败则返回 FALSE。

  n、XMLWriter::writeCData

  作用:写标签属性

  用法:XMLWriter::writeCData (resource xmlwriter, string content )

  参数:xmlwriter,xml资源;value,文本值

  返回:如果成功则返回 true,失败则返回 FALSE。

  o、XMLWriter::text

  作用:写文本

  用法:XMLWriter::text (string content )

  参数:content,文本值

  返回:如果成功则返回 true,失败则返回 FALSE。

  p、XMLWriter::flush

  作用:清空缓存

  用法:XMLWriter::flush ( )

  参数:无

  返回:如果成功则返回 true,失败则返回 FALSE。

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1249
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

See all articles