天天看点

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

把从SQL中取出的数据转化成XMl格式

更新时间:2006年10月09日 00:00:00   作者:

使用了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

|// | [email protected] 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 $

class XML_sql2xml {

var $nested = True;

var $tagNameResult = "result";

var $tagNameRow = "row";

var $db = Null;

var $user_options = array();

var $xmldoc;

var $xmlroot;

var $user_tableInfo = array();

var $encoding_from  = "ISO-8859-1";

var $encoding_to = "gb2312";

var $tagname = "tagname";

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";

}

}

}

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);

}

}

function addXmlFile($file,$xpath = Null)

{

$fd = fopen( $file, "r" );

$content = fread( $fd, filesize( $file ) );

fclose( $fd );

$this->doXmlString2Xml($content,$xpath);

}

相关文章

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

动态生成gif格式的图像要注意?...2006-10-10

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

php注入实例...2006-10-10

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

一个用于网络的工具函数库...2006-10-10

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

如何使用PHP中的字符串函数...2006-10-10

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

在php中使用sockets:从新闻组中获取文章...2006-10-10

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

由于按照条件提取多台服务器生成的报表数据的需要,我们很可能用到php动态生成可以跨行跨列的表格,table跨行跨列杂糅在一起经常出现不好控制,而且行列合并属性的逻辑耦合度很高,所以对于这次的需要就有了如下东西2012-11-11

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

文章推荐系统(三)...2006-10-10

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

新手学PHP之数据库操作详解及乱码解决!...2007-01-01

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

基于mysql的论坛(2)...2006-10-10

java将sql数据转xml文件_把从SQL中取出的数据转化成XMl格式

用PHP生成PDF文件 with FPDF...2006-10-10

最新评论