Home Backend Development PHP Tutorial PHP xml commonly used functions_PHP tutorial

PHP xml commonly used functions_PHP tutorial

Jul 21, 2016 pm 02:51 PM
dom php s xml effect function load Encyclopedia Commonly used document usage

1. DOM function

a. DOMDocument->load()

Function: Load xml file

Usage: DOMDocument->load( string filename )

Parameters: filename, xml file;

Return: TRUE if successful, FALSE if failed.

b. DOMDocument->loadXML()

Function: Load xml code

Usage: DOMDocument->loadXML( string source )

Parameters: source xml code;

Return: TRUE if successful, FALSE if failed.

c. DOMDocument->getElementsByTagName_r()

Function: Search

by tag name

Usage: DOMDocument->getElementsByTagName_r(string name)

Parameters: name, label name;

Return: new DOMNodeList object.

d. DOMDocument->getElementById()

Function: Search

by tag name

Usage: DOMDocument->getElementById(string elementId)

Parameters: elementId, tag id;

Return: new DOMNodeList object.

e.DOMDocument->createElement_x_x()

Function: Create tags

Usage: DOMDocument->createElement_x_x(string name [, string value] )

Parameters: name, tag name, value, only;

Return: new DOMElement object, false on failure.

 f. DOMDocument->createTextNode()

Function: Create text node

Usage: DOMDocument->createTextNode(string content)

Parameters: content, content;

Return: new DOMText object, false on failure.

h. DOMDocument->createCDATASection()

Function: Create cdata node

Usage: DOMDocument->createCDATASection( string data)

Parameters: data, content;

Return: new DOMCDATASection object, false on failure.

i. DOMDocument->createAttribute()

Function: Create label attributes

Usage: DOMDocument->createAttribute(string name)

Parameters: name, attribute name;

Return: new DOMAttr object, false on failure.

j.DOMDocument->validate()

Function: Check xml code

Usage: DOMDocument->validate()

Parameters: None

Return: TRUE if successful, FALSE if failed.

k、DOMDocument->save()

Function: Save xml code to xml file

Usage: DOMDocument->save(string filename)

Parameters: filename, xml file;

Return: Returns the xml character length if successful, false if failed.

l. DOMDocument->saveXML()

Function: Save xml code

Usage: DOMDocument->saveXML([DOMNode node [, int options]])

Parameters: node, DOMNode;

Return: Return xml if successful, false if failed.

m、DOMElement->hasAttribute()

Function: Detect whether the attribute exists

Usage: DOMElement->hasAttribute(string name)

Parameters: name, attribute name;

Return: TRUE if successful, FALSE if failed.

n. DOMElement->getAttribute()

Function: Get attribute value

Usage: DOMElement->getAttribute(string name)

Parameters: name, attribute name;

Return: The attribute value is returned on success, and empty on failure.

o.DOMElement->getAttribute()

Function: Get attribute value

Usage: DOMElement->getAttribute(string name)

Parameters: name, attribute name;

Return: The attribute value is returned on success, and empty on failure.

p、DOMElement->setAttribute()

Function: Set attribute value

Usage: DOMElement->setAttribute(string name, string value)

Parameters: name, attribute name; value, attribute value

Return: TRUE if successful, FALSE if failed.

q、DOMNode->appendChild()

Function: Link child nodes to parent nodes

Usage: DOMNode->appendChild(DOMNode newnode)

Parameters: newnode, new node;

Return: Return a new node if successful, return empty if failed.

r、DOMNode->hasAttributes()

Function: Check whether there are attributes

Usage: DOMNode->hasAttributes( )

Parameters: None

Return: TRUE if successful, FALSE if failed.

 s, DOMNode->hasChildNodes()

Function: Check whether there are child nodes

Usage: DOMNode->hasChildNodes()

Parameters: None

Return: TRUE if successful, FALSE if failed.

 t、DOMNode->insertBefore()

Function: Insert the child node into the DOM tree in front of a certain node

Usage: DOMNode->insertBefore(DOMNode newnode [, DOMNode refnode] )

Parameters: newnode, new node; refnode, reference node

Return: Returns a new node if successful, returns empty if failed.

u. DOMNode->removeChild()

Function: Delete child nodes

Usage: DOMNode->removeChild(DOMNode oldnode)

Parameters: oldnode, child node;

Return: Returns child nodes on success, returns empty on failure.

v. DOMNode->replaceChild()

Function: Update child nodes

Usage: DOMNode->replaceChild(DOMNode newnode, DOMNode oldnode)

Parameters: newnode, new node; oldnode, old node

Return: Return oldnode on success, empty on failure.

 ————————-DOMNode attribute————————————–

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 the parent node of the node

f. DOMNode->childNodes

Function: Get node child nodes

g、DOMNode->firstChild

Function: Get the first child node of the node

h、DOMNode->lastChild

Function: Get the last child node of the 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: TRUE if successful, 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: TRUE if successful, FALSE if failed.

c. XMLReader::read

Function: Read xml and make the parser advance to the next tag

Usage: XMLReader::read(), traverse the entire document in a while loop

Parameter: NULL

Return: TRUE if successful, FALSE if failed.

 d. XMLReader::getAttribute

Function: Get attributes

Usage: XMLReader::getAttribute(string name)

Parameters: name, attribute name

Return: Returns the attribute value if successful, returns FALSE if failed.

e. XMLReader::isValid

Function: Check whether the xml is legal

Usage: XMLReader::isValid()

Parameters: None

Return: true if successful, FALSE if failed.

 f. XMLReader::moveToAttribute

Function: Move focus to the pointed attribute

Usage: XMLReader::moveToAttribute(string name)

Parameters: name, attribute name

Return: true if successful, FALSE if failed.

g、XMLReader::moveToFirstAttribute

Function: Move focus to the first attribute

Usage: XMLReader::moveToFirstAttribute()

Parameters: None

Return: true if successful, FALSE if failed.

h、XMLReader::moveToNextAttribute

Function: Move focus to the next attribute

Usage: XMLReader::moveToNextAttribute()

Parameters: None

Return: true if successful, FALSE if failed.

i. XMLReader::moveToElement

Function: Move focus to the current attribute of the parent node

Usage: XMLReader::moveToElement()

Parameters: None

Return: true if successful, FALSE if failed.

j、XMLReader::close

Function: Close xml input

Usage: XMLReader::close()

Parameters: None

Return: true if successful, 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::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 ;

Function: Number of attributes

b. XMLReader->baseURI;

Function: node url

c. XMLReader->depth ;

Function: The number of layers of the node tree

 d. XMLReader->hasAttributes;

Function: Check whether there are attributes

e. XMLReader->hasValue;

Function: Whether it has value

 f. XMLReader->isEmptyElement;

Function: Whether it is an empty tag

g、XMLReader->localName;

Function: Label inside the label

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)

Parameters: url xml address

Return: true if successful, FALSE if failed.

b. XMLWriter::setIndentString

Function: Set the indent character

Usage: XMLWriter::setIndentString(string indentString)

Parameter: indentString indent character

Return: true if successful, FALSE if failed.

c. XMLWriter::setIndent

Function: Set the indent switch

Usage: XMLWriter::setIndent(bool indent)

Parameter: indent whether to indent or not

Return: 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: true if successful, FALSE if failed.

 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: true if successful, FALSE if failed.

h、XMLWriter::startElement

Function: Set the start tag

Usage: XMLWriter::startElement(string name)

Parameters: name, label name

Return: true if successful, FALSE if failed.

i. XMLWriter::endElement

Function: Set the closing tag

Usage: XMLWriter::endElement()

Parameters: None

Return: true if successful, FALSE if failed.

j、XMLWriter::startCData

Function: Set the start tag

Usage: XMLWriter::startCData()

Parameters: None

Return: true if successful, FALSE if failed.

k、XMLWriter::endCData

Function: Set the closing tag

Usage: XMLWriter::endCData ()

Parameters: None

Return: true if successful, FALSE if failed.

l. XMLWriter::writeAttribute

Function: Write tag attributes

Usage: XMLWriter::writeAttribute (string name, string value)

Parameters: name, attribute name; value, attribute value

Return: 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

Return: true if successful, FALSE if failed.

o、XMLWriter::text

Function: Write text

Usage: XMLWriter::text (string content)

Parameters: content, text value

Return: true if successful, FALSE if failed.

p、XMLWriter::flush

Function: Clear cache

Usage: XMLWriter::flush ( )

Parameters: None

Return: true if successful, FALSE if failed.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371785.htmlTechArticle1. DOM function a. DOMDocument-load() Function: Load xml file Usage: DOMDocument-load( string filename ) Parameters: filename, xml file; Return: TRUE if successful, failed...
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 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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

See all articles