把从SQL中取出的数据转化成XMl格式
xml|数据
使用了php的PEAR和DB
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Christian Stocker
// +----------------------------------------------------------------------+
//
// $Id: sql2xml.php,v 1.59 2001/11/13 10:54:02 chregu Exp $
/**
* This class takes a PEAR::DB-Result Object, a sql-query-string or an array
* and returns a xml-representation of it.
*
* TODO
* -encoding etc, options for header
* -ERROR CHECKING
*
* Usage example
*
* include_once ("DB.php");
* include_once("XML/sql2xml.php");
* $db = DB::connect("mysql://root@localhost/xmltest");
* $sql2xml = new xml_sql2xml();
* //the next one is only needed, if you need others than the default
* $sql2xml->setEncoding("ISO-8859-1","UTF-8");
* $result = $db->query("select * from bands");
* $xmlstring = $sql2xml->getXML($result);
*
* or
*
* include_once ("DB.php");
* include_once("XML/sql2xml.php");
* $sql2xml = new xml_sql2xml("mysql://root@localhost/xmltest");
* $sql2xml->Add("select * from bands");
* $xmlstring = $sql2xml->getXML();
*
* More documentation and a tutorial/how-to can be found at
* http://php.chregu.tv/sql2xml
*
* @author Christian Stocker
* @version $Id: sql2xml.php,v 1.59 2001/11/13 10:54:02 chregu Exp $
* @package XML
*/
class XML_sql2xml {
/**
* If joined-tables should be output nested.
* Means, if you have joined two or more queries, the later
* specified tables will be nested within the result of the former
* table.
* Works at the moment only with mysql automagically. For other RDBMS
* you have to provide your table-relations by hand (see user_tableinfo)
*
* @var boolean
* @see $user_tableinfo, doSql2Xml(), doArray2Xml();
*/
var $nested = True;
/**
* Name of the tag element for resultsets
*
* @var string
* @see insertNewResult()
*/
var $tagNameResult = "result";
/**
* Name of the tag element for rows
*
* @var string
* @see insertNewRow()
*/
var $tagNameRow = "row";
/**
*
* @var object PEAR::DB
* @access private
*/
var $db = Null;
/**
* Options to be used in extended Classes (for example in sql2xml_ext).
* They are passed with SetOptions as an array (arrary("user_options" = array());
* and can then be accessed with $this->user_options["bla"] from your
* extended classes for additional features.
* This array is not use in this base class, it's only for passing easy parameters
* to extended classes.
*
* @var array
*/
var $user_options = array();
/**
* The DomDocument Object to be used in the whole class
*
* @var object DomDocument
* @access private
*/
var $xmldoc;
/**
* The Root of the domxml object
* I'm not sure, if we need this as a class variable....
* could be replaced by domxml_root($this->xmldoc);
*
* @var object DomNode
* @access private
*/
var $xmlroot;
/**
* This array is used to give the structure of your database to the class.
* It's especially useful, if you don't use mysql, since other RDBMS than
* mysql are not able at the moment to provide the right information about
* your database structure within the query. And if you have more than 2
* tables joined in the sql it's also not possible for mysql to find out
* your real relations.
* The parameters are the same as in fieldInfo from the PEAR::DB and some
* additional ones. Here they come:
* From PEAR::DB->fieldinfo:
*
* $tableInfo[$i]["table"] : the table, which field #$i belongs to.
* for some rdbms/comples queries and with arrays, it's impossible
* to find out to which table the field actually belongs. You can
* specify it here more accurate. Or if you want, that one fields
* belongs to another table, than it actually says (yes, there's
* use for that, see the upcoming tutorial ...)
*
* $tableInfo[$i]["name"] : the name of field #$i. if you want another
* name for the tag, than the query or your array provides, assign
* it here.
*
* Additional info
* $tableInfo["parent_key"][$table] : index of the parent key for $table.
* this is the field, where the programm looks for changes, if this
* field changes, it assumes, that we need a new "rowset" in the
* parent table.
*
* $tableInfo["parent_table"][$table]: name of the parent table for $table.
*
* @var array
* @access private
*/
var $user_tableInfo = array();
/**
* the encoding type, the input from the db has
*/
var $encoding_from = "ISO-8859-1";
/**
* the encoding type, the output in the xml should have
* (note that domxml at the moment only support UTF-8, or at least it looks like)
*/
var $encoding_to = "gb2312";
var $tagname = "tagname";
/**
* Constructor
* The Constructor can take a Pear::DB "data source name" (eg.
* "mysql://user:passwd@localhost/dbname") and will then connect
* to the DB, or a PEAR::DB object link, if you already connected
* the db before.
" If you provide nothing as $dsn, you only can later add stuff with
* a pear::db-resultset or as an array. providing sql-strings will
* not work.
* the $root param is used, if you want to provide another name for your
* root-tag than "root". if you give an empty string (""), there will be no
* root element created here, but only when you add a resultset/array/sql-string.
* And the first tag of this result is used as the root tag.
*
* @param mixed $dsn PEAR::DB "data source name" or object DB object
* @param string $root the name of the xml-doc root element.
* @access public
*/
function XML_sql2xml ($dsn = Null, $root = "root") {
// if it's a string, then it must be a dsn-identifier;
if (is_string($dsn))
{
include_once ("DB.php");
$this->db = DB::Connect($dsn);
if (DB::isError($this->db))
{
print "The given dsn for XML_sql2xml was not valid in file ".__FILE__." at line ".__LINE__."
\n";
return new DB_Error($this->db->code,PEAR_ERROR_DIE);
}
}
elseif (is_object($dsn) && DB::isError($dsn))
{
print "The given param for XML_sql2xml was not valid in file ".__FILE__." at line ".__LINE__."
\n";
return new DB_Error($dsn->code,PEAR_ERROR_DIE);
}
// if parent class is db_common, then it's already a connected identifier
elseif (get_parent_class($dsn) == "db_common")
{
$this->db = $dsn;
}
$this->xmldoc = domxml_new_xmldoc('1.0');
//oehm, seems not to work, unfortunately.... does anybody know a solution?
$this->xmldoc->encoding = $this->encoding_to;
if ($root) {
$this->xmlroot = $this->xmldoc->add_root($root);
//PHP 4.0.6 had $root->name as tagname, check for that here...
if (!isset($this->xmlroot->{$this->tagname}))
{
$this->tagname = "name";
}
}
}
/**
* General method for adding new resultsets to the xml-object
* Give a sql-query-string, a pear::db_result object or an array as
* input parameter, and the method calls the appropriate method for this
* input and adds this to $this->xmldoc
*
* @param string sql-string, or object db_result, or array
* @param mixed additional parameters for the following functions
* @access public
* @see addResult(), addSql(), addArray(), addXmlFile()
*/
function add ($resultset, $params = Null)
{
// if string, then it's a query, a xml-file or a xml-string...
if (is_string($resultset)) {
if (preg_match("/\.xml$/",$resultset)) {
$this->AddXmlFile($resultset,$params);
}
elseif (preg_match("/.*select.*from.*/i" , $resultset)) {
$this->AddSql($resultset);
}
else {
$this->AddXmlString($resultset);
}
}
// if array, then it's an array...
elseif (is_array($resultset)) {
$this->AddArray($resultset);
}
if (get_class($resultset) == "db_result") {
$this->AddResult($resultset);
}
}
/**
* Adds the content of a xml-file to $this->xmldoc, on the same level
* as a normal resultset (mostly just below
*
* @param string filename
* @param mixed xpath either a string with the xpath expression or an array with "xpath"=>xpath expression and "root"=tag/subtag/etc, which are the tags to be inserted before the result
* @access public
* @see doXmlString2Xml()
*/
function addXmlFile($file,$xpath = Null)
{
$fd = fopen( $file, "r" );
$content = fread( $fd, filesize( $file ) );
fclose( $fd );
$this->doXmlString2Xml($content,$xpath);
}
/**
* Adds the content of a xml-string to $this->xmldoc, on the same level
* as a normal resultset (mostly just below
*
* @param string xml
* @param mixed xpath either a string with the xpath expression or an array with "xpath"=>xpath expression and "root"=tag/subtag/etc, which are the tags to be inserted before the result
* @access public
* @see doXmlString2Xml()
*/

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

“你的组织要求你更改PIN消息”将显示在登录屏幕上。当在使用基于组织的帐户设置的电脑上达到PIN过期限制时,就会发生这种情况,在该电脑上,他们可以控制个人设备。但是,如果您使用个人帐户设置了Windows,则理想情况下不应显示错误消息。虽然情况并非总是如此。大多数遇到错误的用户使用个人帐户报告。为什么我的组织要求我在Windows11上更改我的PIN?可能是您的帐户与组织相关联,您的主要方法应该是验证这一点。联系域管理员会有所帮助!此外,配置错误的本地策略设置或不正确的注册表项也可能导致错误。即

Windows11将清新优雅的设计带到了最前沿;现代界面允许您个性化和更改最精细的细节,例如窗口边框。在本指南中,我们将讨论分步说明,以帮助您在Windows操作系统中创建反映您的风格的环境。如何更改窗口边框设置?按+打开“设置”应用。WindowsI转到个性化,然后单击颜色设置。颜色更改窗口边框设置窗口11“宽度=”643“高度=”500“>找到在标题栏和窗口边框上显示强调色选项,然后切换它旁边的开关。若要在“开始”菜单和任务栏上显示主题色,请打开“在开始”菜单和任务栏上显示主题

默认情况下,Windows11上的标题栏颜色取决于您选择的深色/浅色主题。但是,您可以将其更改为所需的任何颜色。在本指南中,我们将讨论三种方法的分步说明,以更改它并个性化您的桌面体验,使其具有视觉吸引力。是否可以更改活动和非活动窗口的标题栏颜色?是的,您可以使用“设置”应用更改活动窗口的标题栏颜色,也可以使用注册表编辑器更改非活动窗口的标题栏颜色。若要了解这些步骤,请转到下一部分。如何在Windows11中更改标题栏的颜色?1.使用“设置”应用按+打开设置窗口。WindowsI前往“个性化”,然

任务栏缩略图可能很有趣,但它们也可能分散注意力或烦人。考虑到您将鼠标悬停在该区域的频率,您可能无意中关闭了重要窗口几次。另一个缺点是它使用更多的系统资源,因此,如果您一直在寻找一种提高资源效率的方法,我们将向您展示如何禁用它。不过,如果您的硬件规格可以处理它并且您喜欢预览版,则可以启用它。如何在Windows11中启用任务栏缩略图预览?1.使用“设置”应用点击键并单击设置。Windows单击系统,然后选择关于。点击高级系统设置。导航到“高级”选项卡,然后选择“性能”下的“设置”。在“视觉效果”选

在Windows11上的显示缩放方面,我们都有不同的偏好。有些人喜欢大图标,有些人喜欢小图标。但是,我们都同意拥有正确的缩放比例很重要。字体缩放不良或图像过度缩放可能是工作时真正的生产力杀手,因此您需要知道如何对其进行自定义以充分利用系统功能。自定义缩放的优点:对于难以阅读屏幕上的文本的人来说,这是一个有用的功能。它可以帮助您一次在屏幕上查看更多内容。您可以创建仅适用于某些监视器和应用程序的自定义扩展配置文件。可以帮助提高低端硬件的性能。它使您可以更好地控制屏幕上的内容。如何在Windows11

屏幕亮度是使用现代计算设备不可或缺的一部分,尤其是当您长时间注视屏幕时。它可以帮助您减轻眼睛疲劳,提高易读性,并轻松有效地查看内容。但是,根据您的设置,有时很难管理亮度,尤其是在具有新UI更改的Windows11上。如果您在调整亮度时遇到问题,以下是在Windows11上管理亮度的所有方法。如何在Windows11上更改亮度[10种方式解释]单显示器用户可以使用以下方法在Windows11上调整亮度。这包括使用单个显示器的台式机系统以及笔记本电脑。让我们开始吧。方法1:使用操作中心操作中心是访问

XML文件可以用PPT打开吗?XML,即可扩展标记语言(ExtensibleMarkupLanguage),是一种被广泛应用于数据交换和数据存储的通用标记语言。与HTML相比,XML更加灵活,能够定义自己的标签和数据结构,使得数据的存储和交换更加方便和统一。而PPT,即PowerPoint,是微软公司开发的一种用于创建演示文稿的软件。它提供了图文并茂的方

在iOS17中,Apple为其移动操作系统引入了几项新的隐私和安全功能,其中之一是能够要求对Safari中的隐私浏览选项卡进行二次身份验证。以下是它的工作原理以及如何将其关闭。在运行iOS17或iPadOS17的iPhone或iPad上,如果您在Safari浏览器中打开了任何“无痕浏览”标签页,然后退出会话或App,Apple的浏览器现在需要面容ID/触控ID认证或密码才能再次访问它们。换句话说,如果有人在解锁您的iPhone或iPad时拿到了它,他们仍然无法在不知道您的密码的情况下查看您的隐私
