db에서 xml 로 추출할떄 사용
컨텐츠 정보
- 17,308 조회
- 3 추천
- 목록
본문
---------------------------------------------------------------
class Xmlmake
{
var $data;
var $path;
var $filename;
var $type;
// xml 내용만들기
function xmlContents($colum, $start, $data_vars)
{
$count = sizeof($colum);
for($i=$start; $i<$count -1; $i++)
{
$Element = $colum[$i];
foreach($colum["run"] as $key => $value)
{
$tmp .= "<".$value.">".str_replace("#169;", "&", $data_vars[$value])."</".$value.">\\n";
}
}
return $date = "<{$Element}>\\n".$tmp."</{$Element}>\\n";
}
//$path : 파일경로
//$filename : 파일명
// $type : w,r
//$encoding : UTF-8
function xmlFile()
{
if (!($fp = @fopen($this->path."/".$this->filename, $this->type)))
{
die("XMLmake : {$this->filename} 을 열수 없습니다.");
}
if(!@fwrite($fp, $this->data)) die("Xmlmake : xmlFile : write 실패");
fclose($fp);
}
// query 문만 있으면 그냥 한바퀴, $info_query 있으면 for문 2번돈다.
function xmlMInit($path, $filename, $type, &$claSQL, $query, $colum, $start=1, $encoding="UTF-8", $info_query, $info_orderby)
{
$this->path = $path;
$this->filename = $filename;
$this->type = $type;
$result = $claSQL->query($query);
$cnt = $claSQL->rows();
for($i=0; $i<$cnt; $i++)
{
$list = $claSQL->fetch_array($result);
$tmp .= $this->xmlContents($colum, $start, $list);
if(!empty($info_query))
{
$info_r_query = $info_query." WHERE p_uid='$list[uid]' ".$info_orderby;
$info_result = $claSQL->query($info_r_query);
$info_cnt = $claSQL->rows();
for($j=0; $j<$info_cnt; $j++)
{
$list_info = $claSQL->fetch_array($info_result);
$tmp .= $this->xmlContents($colum, $start, $list_info);
}
}
}
$_data = "<?xml version=\\"1.0\\" encoding=\\"{$encoding}\\"?>";
$_data = $_data."\\n";
$_data = $_data."<DATA>\\n".$tmp."</DATA>";
$this->data = $_data;
}
}
아래처럼 출력됩니다.
단 탭키는 없음
<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<ARTICLE>
<uid>8</uid>
<p_uid>0</p_uid>
<ctgname>일반회원</ctgname>
<url>#</url>
<depth>0</depth>
<level>8</level>
<access_id></access_id>
<photo></photo>
</ARTICLE>
<ARTICLE>
<uid>1</uid>
<p_uid>0</p_uid>
<ctgname>관리자명단</ctgname>
<url>./administer/</url>
<depth>0</depth>
<level>8</level>
<access_id></access_id>
<photo></photo>
</ARTICLE>
<ARTICLE>
<uid>9</uid>
<p_uid>8</p_uid>
<ctgname>가나다찾기</ctgname>
<url>./member/</url>
<depth>1</depth>
<level>8</level>
<access_id></access_id>
<photo></photo>
</ARTICLE>
</DATA>
class Xmlmake
{
var $data;
var $path;
var $filename;
var $type;
// xml 내용만들기
function xmlContents($colum, $start, $data_vars)
{
$count = sizeof($colum);
for($i=$start; $i<$count -1; $i++)
{
$Element = $colum[$i];
foreach($colum["run"] as $key => $value)
{
$tmp .= "<".$value.">".str_replace("#169;", "&", $data_vars[$value])."</".$value.">\\n";
}
}
return $date = "<{$Element}>\\n".$tmp."</{$Element}>\\n";
}
//$path : 파일경로
//$filename : 파일명
// $type : w,r
//$encoding : UTF-8
function xmlFile()
{
if (!($fp = @fopen($this->path."/".$this->filename, $this->type)))
{
die("XMLmake : {$this->filename} 을 열수 없습니다.");
}
if(!@fwrite($fp, $this->data)) die("Xmlmake : xmlFile : write 실패");
fclose($fp);
}
// query 문만 있으면 그냥 한바퀴, $info_query 있으면 for문 2번돈다.
function xmlMInit($path, $filename, $type, &$claSQL, $query, $colum, $start=1, $encoding="UTF-8", $info_query, $info_orderby)
{
$this->path = $path;
$this->filename = $filename;
$this->type = $type;
$result = $claSQL->query($query);
$cnt = $claSQL->rows();
for($i=0; $i<$cnt; $i++)
{
$list = $claSQL->fetch_array($result);
$tmp .= $this->xmlContents($colum, $start, $list);
if(!empty($info_query))
{
$info_r_query = $info_query." WHERE p_uid='$list[uid]' ".$info_orderby;
$info_result = $claSQL->query($info_r_query);
$info_cnt = $claSQL->rows();
for($j=0; $j<$info_cnt; $j++)
{
$list_info = $claSQL->fetch_array($info_result);
$tmp .= $this->xmlContents($colum, $start, $list_info);
}
}
}
$_data = "<?xml version=\\"1.0\\" encoding=\\"{$encoding}\\"?>";
$_data = $_data."\\n";
$_data = $_data."<DATA>\\n".$tmp."</DATA>";
$this->data = $_data;
}
}
아래처럼 출력됩니다.
단 탭키는 없음
<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<ARTICLE>
<uid>8</uid>
<p_uid>0</p_uid>
<ctgname>일반회원</ctgname>
<url>#</url>
<depth>0</depth>
<level>8</level>
<access_id></access_id>
<photo></photo>
</ARTICLE>
<ARTICLE>
<uid>1</uid>
<p_uid>0</p_uid>
<ctgname>관리자명단</ctgname>
<url>./administer/</url>
<depth>0</depth>
<level>8</level>
<access_id></access_id>
<photo></photo>
</ARTICLE>
<ARTICLE>
<uid>9</uid>
<p_uid>8</p_uid>
<ctgname>가나다찾기</ctgname>
<url>./member/</url>
<depth>1</depth>
<level>8</level>
<access_id></access_id>
<photo></photo>
</ARTICLE>
</DATA>
관련자료
-
링크
댓글 0
등록된 댓글이 없습니다.