A very handy XML class! ! Original_PHP Tutorial
// I am not familiar with XML, and the description of XML may be wrong in the annotation
// This is just an idea. To be implemented, it should be slightly modified. Some data that are not commonly queried using XML can be used. Save
// For example, user information in a virtual community will generally be displayed only if the user himself or another user specifies his USERNAME
// The rest requires opening, querying, interpreting data sets, and closing the database every time consumption.
define("enter",chr(13).chr(10));
class DATA_XML //Key! ! ! A custom class
{
var $parser; //XML interpreter
var $tags; //XML tags
var $on; //
var $root; // root Element
var $Data = array(); // Element array
function DATA_XML($filename,$root) //Class initial function filename file name, root root element
{
$this->root = $root; //Initial root element
$this->parser = xml_parser_create();//Create interpretation object
xml_set_object(&$this->parser,&$this );//Set object
xml_set_element_handler($this->parser,"tag_on","tag_off");//Set element management function
xml_set_character_data_handler($this->parser,"getdata"); //Set data management events
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); //Requires strict case sensitivity
if( file_exists($filename) ) //File found?
{//Find
$fp = fopen($filename,"r"); //Open for read only
$c = fread($fp,filesize($filename)); //Read data
fclose($fp);//Close
$this->parse($c); //Set the interpretation object
}
else
{
echo "ooooo "; //! ? ! It seems to be used for debugging, just remove the else
}
}
function parse($data)//Explanation function
{
xml_parse ($this->parser,$data);
}
function tag_on($parser,$tag,$attributes)//Discover element trigger function
{
$this- >on = true; // Already triggered
$this->tags = $tag;
//echo $tag;
}
function tag_off($parser,$ tag) //Element binding function
{
$this->on = false; // Element binding
}
function getdata($parser,$cdata) // Take out the element
{
if($this->on && $this->tags!=$this->root)
{//It is better to verify, (whether it is an element now starting, and not the root element? )
$this->Data[$this->tags]=trim($cdata);
! Use tags to make an array table and add data to the array elements
//echo trim($cdata);
//echo $this->tags;
//echo "n";
}
}
function check($str)
{//Check character
if( strlen($str)<1)//If it is a null character
return ' ' ;//Return ' '
else
return $str;//Otherwise return to the original path (otherwise the XML will not seem to have an end tag)
}
function saveas($filename)//Save as For
{
$c=''.enter; ",chr(13).chr(10));
$c.="<".$this->root.">".enter;
for( reset($this->Data);$i=key($this->Data);next($this->Data))
{//Start to list all the data
$c.= "<".$i.">".$this->check($this->Data[$i])."".$i."> ;".enter;
// Use the array table name as the element label and add the data content
}
//echo $c;
$c.="".$ this->root.">".enter;//End tag
$fp = fopen( $filename , "w" );//Write file
fwrite($fp,$c);
fclose($fp);
}
};
/*New key an XML file
DATA_XML(path."arm.xml","DATA"/*root element*/);
$xml->Data["UserName"]="Guan Yu";
$xml->Data[ "Nick"]="Guan Yunchang";
$xml->saveas(path."arm.xml");
unset( $xml );
// Read a file
$ xml = new DATA_XML(path."arm.xml","DATA");
echo $xml->Data["Nick"];//Show it?
$xml->Data["Nick"]="Master Guan";//UPDATE
$xml->Data["Master"]="Liu Bei";//INSERT INTO
$ xml->saveas(path."arm.xml");//Save as overwrite itself
*/
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

Convert XML data in Python to CSV format XML (ExtensibleMarkupLanguage) is an extensible markup language commonly used for data storage and transmission. CSV (CommaSeparatedValues) is a comma-delimited text file format commonly used for data import and export. When processing data, sometimes it is necessary to convert XML data to CSV format for easy analysis and processing. Python is a powerful

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

Glodon Software is a software company focusing on the field of building informatization. Its products are widely used in all aspects of architectural design, construction, and operation. Due to the complex functions and large data volume of Glodon software, it requires high computer configuration. This article will elaborate on the computer configuration recommendations of Glodon Software from many aspects to help readers choose a suitable computer configuration processor. Glodon Software requires a large amount of data calculation and processing when performing architectural design, simulation and other operations. Therefore, the requirements for the processor are higher. It is recommended to choose a multi-core, high-frequency processor, such as Intel i7 series or AMD Ryzen series. These processors have strong computing power and multi-thread processing capabilities, and can better meet the needs of Glodon software. Memory Memory is affecting computing

How to handle XML and JSON data formats in C# development requires specific code examples. In modern software development, XML and JSON are two widely used data formats. XML (Extensible Markup Language) is a markup language used to store and transmit data, while JSON (JavaScript Object Notation) is a lightweight data exchange format. In C# development, we often need to process and operate XML and JSON data. This article will focus on how to use C# to process these two data formats, and attach

Using Python to implement data validation in XML Introduction: In real life, we often deal with a variety of data, among which XML (Extensible Markup Language) is a commonly used data format. XML has good readability and scalability, and is widely used in various fields, such as data exchange, configuration files, etc. When processing XML data, we often need to verify the data to ensure the integrity and correctness of the data. This article will introduce how to use Python to implement data verification in XML and give the corresponding
