一个很方便的 XML 类!!原创的噢
// 本人不熟悉XML,可能注解对XML的描述有误
// 这只是个思想,要实现的话应该略加修整,可以把一些不常用条件查询的数据用XML保存
// 如虚拟社区的 用户资料,一般只有用户自己或其他用户指定了他的USERNAME才会显示
// 剩下每次都要开启、查询、解释数据集、关闭数据库的消耗。
define("enter",chr(13).chr(10));
class DATA_XML //关键!!!一个自定义类
{
var $parser; //XML解释器
var $tags; //XML标签
var $on; //
var $root; // 根元素
var $Data = array(); // 元素数组
function DATA_XML($filename,$root) //类初始函数 filename文件名,root根元素
{
$this->root = $root; // 初始根元素
$this->parser = xml_parser_create();//创建解释对象
xml_set_object(&$this->parser,&$this);//设置对象
xml_set_element_handler($this->parser,"tag_on","tag_off");//设置元素管理函数
xml_set_character_data_handler($this->parser,"getdata"); //设置数据管理事件
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); //要求严格区分大小写
if( file_exists($filename) ) //找到文件吗?
{//找到
$fp = fopen($filename,"r"); // 只读打开
$c = fread($fp,filesize($filename)); //读取数据
fclose($fp);//关闭
$this->parse($c); //设置解释对象
}
else
{
echo "ooooo"; //!?!好象是调试时用的,去掉 else好了
}
}
function parse($data)//解释函数
{
xml_parse($this->parser,$data);
}
function tag_on($parser,$tag,$attributes)//发现元素触发函数
{
$this->on = true; // 已经触发过
$this->tags = $tag;
//echo $tag;
}
function tag_off($parser,$tag) //元素结素函数
{
$this->on = false; // 元素结素
}
function getdata($parser,$cdata) //取出元素
{
if($this->on && $this->tags!=$this->root)
{//验证一下比较好,(现在是否为元素的开始,并且不是根元素?)
$this->Data[$this->tags]=trim($cdata);
// 关键啊!!用标签做数组表,并给这个数组元素付上数据
//echo trim($cdata);
//echo $this->tags;
//echo "\n";
}
}
function check($str)
{//检查字符
if( strlen($str)return ' ';//返回 ' '
else
return $str;//否则原路返回(不然XML好象会不做结束标记)
}
function saveas($filename)//另存为
{
$c=''.enter;
//这个不用说了吧,enter是define("enter",chr(13).chr(10));
$c.="root.">".enter;
//首先设定一下根元素
for( reset($this->Data);$i=key($this->Data);next($this->Data))
{//开始举出所有数据啦
$c.= "".$this->check($this->Data[$i])."".$i.">".enter;
// 用数组表名做元素标签,并加上数据内容
}
//echo $c;
$c.="".$this->root.">".enter;//结束标签
$fp = fopen( $filename , "w" );//写入文件
fwrite($fp,$c);
fclose($fp);
}
};
/*新键一个XML文件
$xml = new DATA_XML(路径."arm.xml","DATA"/*根元素*/);
$xml->Data["UserName"]="关羽";
$xml->Data["Nick"]="关云长";
$xml->saveas( 路径."arm.xml");
unset( $xml );
// 读取一个文件
$xml = new DATA_XML(路径."arm.xml","DATA");
echo $xml->Data["Nick"];//显示一下?
$xml->Data["Nick"]="关老爷";//UPDATE
$xml->Data["Master"]="刘备";//INSERT INTO
$xml->saveas(路径."arm.xml");//另存为覆盖本身
*/
?>

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

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

PHP error: Unable to declare class repeatedly, solution! It is common for developers to encounter problems. In PHP development, we often encounter a common error: the class cannot be declared repeatedly. This problem seems simple, but if not solved in time, the code will not execute correctly. This article will introduce the cause of this problem and provide a solution for your reference. When we define a class in PHP code, if the same class is defined multiple times in the same file or multiple files, an error that the class cannot be declared repeatedly will occur. This is

Jackson is a Java-based library that is useful for converting Java objects to JSON and JSON to Java objects. JacksonAPI is faster than other APIs, requires less memory area, and is suitable for large objects. We use the writeValueAsString() method of the XmlMapper class to convert the POJO to XML format, and the corresponding POJO instance needs to be passed as a parameter to this method. Syntax publicStringwriteValueAsString(Objectvalue)throwsJsonProcessingExceptionExampleimp
