一个简单的xml类,可以解析和生成xml文件数据
<?php
include('xml.php');
$data = XML_unserialize($xml);
?>
$xml即是xml文件的内容,$data是解析出的数组;
<?php
include('xml.php');
$xml = XML_serialize($data);
?>
以上为使用实例,分别解析xml文档和生成xml格式的数据
xml.php源码
<?php
###################################################################################
#
# XML Library, by Keith Devens, version 1.2b
# http://keithdevens.com/software/phpxml
#
# This code is Open Source, released under terms similar to the Artistic License.
# Read the license at http://keithdevens.com/software/license
#
###################################################################################
###################################################################################
# XML_unserialize: takes raw XML as a parameter (a string)
# and returns an equivalent PHP data structure
###################################################################################
function & XML_unserialize(&$xml){
$xml_parser = &new XML();
$data = &$xml_parser->parse($xml);
$xml_parser->destruct();
return $data;
}
###################################################################################
# XML_serialize: serializes any PHP data structure into XML
# Takes one parameter: the data to serialize. Must be an array.
###################################################################################
function & XML_serialize(&$data, $level = 0, $prior_key = NULL){
if($level == 0){ ob_start(); echo '<?xml version="1.0" ?>',"\n"; }
while(list($key, $value) = each($data))
if(!strpos($key, ' attr')) #if it's not an attribute
#we don't treat attributes by themselves, so for an empty element
# that has attributes you still need to set the element to NULL
if(is_array($value) and array_key_exists(0, $value)){
XML_serialize($value, $level, $key);
}else{
$tag = $prior_key ? $prior_key : $key;
echo str_repeat("\t", $level),'
相关文档:
包位置:android.widget.TextView
XML Attributes
Attribute Name Related Method &n ......
一些字符在 URL 或 XML 文档中使用时有特殊的含义,因此必须针对这些含义对字符做适当编码以使其生效。
URL 中的特殊字符
在 URL 上执行的查询中,特殊字符被指定为 %xx,其中 xx 是字符的十六进制值。下表列出了这些特殊字符并描述了它们的含义。有关更多信息,请参见 http://www.faqs.org/rfcs/rfc1738.html 中的 RFC ......
在最近的项目中,偶遇到一个可以说很小的问题,静下心来,有想把它记下来的冲动,随产生这不成文的几段文字。
在我用ReadXml()和ReadSchema()读取XML文件时,总是出现异常,后来经过调试发现报XmlException异常并提示“缺少根元素&rd ......
---xml拆分以不定空格为分割符号的字符串
--测试数据
if object_id('[tb]') is not null drop table [tb]
create table [tb]([a] varchar(200))
go
insert [tb]
select 'aaaa bbbb cccc dddd'
insert [tb]
select 'eeeeee ffff hhhh   ......