Автор: Пользователь скрыл имя, 01 Мая 2012 в 17:05, курсовая работа
Цель данной работы – исследовать способы хранения XML в базах данных, выявить их достоинства, недостатки, область применения. Для достижения данной цели необходимо решить следующие задачи:
а) выявить особенности языка XML;
б) определить и проанализировать существующие способы хранения XML;
в) определить область применения способов хранения;
г) определить существующие на практике критерии выбора способа хранения;
д) реализовать один из способов хранения XML в базе данных.
Введение
1 ОБЩЕСИСТЕМНЫЙ РАЗДЕЛ
1.1 Языки разметки
1.2 Язык разметки XML
1.2.1 Особенности XML
1.2.2 Синтаксис XML
1.2.3 Структура XML
1.3 Базы данных и системы управления базами данных
1.3.1 Общие понятия о базах данных и системах управления базами данных
1.3.2 Реляционные системы управления базами данных
1.4 Хранение XML
1.4.1 Задача хранения
1.4.2 Документы и данные
1.4.3 Способы хранения XML-документов
1.4.3.1 Хранение в файловой системе
1.4.3.2 Хранение в реляционной базе данных
1.4.3.3 Хранение в БД поддерживающей XML
1.4.3.4 Хранение в специализированных xml-серверах (истинных БД)
1.4.4 Критерии выбора способа хранения
1.5 Обзор готовых продуктов
2 СПЕЦИАЛЬНЫЙ РАЗДЕЛ
2.1 Постановка задачи
2.2 Выбор способа представления XML в РСУБД
2.3 Разработка схемы базы данных
2.4 Выбор средств реализации
2.4.1 Выбор системы управления базами данных
2.4.2 Выбор языка программирования
2.5 Разработка интерфейсного ПО
2.6 Инструкция по применению
ЗАКЛЮЧЕНИЕ
Список использованных источников
Приложение
Приложение А
Приложение Б
$a['nodeRight'] = $counter; $counter = $counter + 1;
$my_record_final->push($a);
}
function contents($parser, $data) {
global $counter;
global $my_record;
$a = $my_record->pop();
$a = $a['itemXML'];
$a['nodeValue'] = $data;
$my_record->push($a);
}
while ($g=@$my_record_final->pop())
{
$g = $g['itemXML'];
$attrs_str = "";
foreach ($g['attrs'] as $name=>$val){
if ( $name != "")
$attrs_str = $attrs_str.$name.'="'.$val.'" ';
}
$val = $g['nodeValue'];
if ( !$result = $mysqli->query("insert into nodesXML values('0','$mid','{$g['
{
printf("Error: %s<br>",$mysqli->error);
exit;
}
}
echo "</pre>";
?>
</body>
</html>
STACK2.CLASS.PHP
<?php
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/
// ------------------------------
// Original Author of file: Carey R. Dayrit <carey.dayrit@gmail.com>
// Version 1.0
// ------------------------------
/**
* A stack data structure. A stack is a LIFO (Last In First Out) data structure.
* This class uses a 2 dimensional array.
*
*Usage Example:
* $my_record=new STACK2('id','name');
* $my_record->push(235,'John');
* $my_record->push(536,'Paul');
* $my_record->push(758,'Mary');
*
* $g=$my_record->pop(); Remove object from top of stack
* $size=$my_record->size();
* $my_record->is_empty(); Checks to see if size is zero
* $g=$my_record->top();Look at object at top of stack, but don't remove
**/
class STACK2{
/*
Generic methods
stack::is_empty()
stack::push()
stack::size()
stack::top()
stack::pop();
*/
var $record;//The Stack data
var $colNames;//array defining column names
var $numCols;//number of columns
var $curStack;//Current Stack
var $nextStack;
//deconstructor for PHP 4 use register_shutdown_function()
//arguments will define the columns of the record
//columns must use associate arrays
function STACK2(){
$this->curStack=-1;
$this->nextStack=0;
//get the number of arguments
$this->numCols = func_num_args();
$this->colNames=func_get_args(
$found_err=0;
foreach($this->colNames as $k){
if(!is_string($k)){
$found_err=1;
}
}
$err_message='RECORD_STACK() argument must be string of data type.';
if($found_err){
return $this->err($err_message);
}
}
function push(){
//push data to the record assuming return error message if arguments are more than the specified column names
//get the number of arguments
$numargs = func_num_args();
//echo $this->nextStack;
if($numargs!=$this->numCols){
$err_message='The number of columns does not match';
return $this->err($err_message);
}else{
$arg_list = func_get_args();
//make the colNames as que
//if there is a better option please do tell me
$name=$this->colNames;
foreach($arg_list as $k){
$d=array_shift($name);
$this->record[$this->
}
$this->curStack=$this->
$this->nextStack++;
}
}
function pop(){
//check if the stack is empty then pop
//echo $this->is_empty();
if($this->is_empty()){
$this->curStack=0;
$err_message='Cannot go further stack is empty';
// $err_message='';
return $this->err($err_message);
}else{
//save the record
$return=$this->record[$this->
//destroy pop array
// $this->record[$this->curStack]
$pig=$this->colNames;
foreach($pig as $d){
array_pop($this->record[$this-
}
$this->nextStack--;
$this->curStack--;
//decrement the pointer;
return $return;
}
}
function size(){
return $this->curStack+1;
}
function top(){
if(!$this->is_empty()){
return $this->record[$this->curStack]
}else{
$err_message='Stack is empty';
return $this->err($err_message);
}
}
function is_empty(){
//get first column name
$dummy=$this->colNames;
//echo $this->record[$this->curStack]
if( $this->curStack == -1 && $this->record[$this->curStack]
return 1;
}else{
return 0;
}
}
function err($message){
// echo "<B>ERROR:</b>".$message;
exit;
}
}
?>
BEAUTIFIER.PHP
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* LICENSE:
*
* Copyright (c) 2003-2008 Stephan Schmidt <schst@php.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category XML
* @package XML_Beautifier
* @author Stephan Schmidt <schst@php.net>
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
* @license http://opensource.org/
* @version CVS: $Id: Beautifier.php,v 1.15 2008/08/24 19:44:14 ashnazg Exp $
* @link http://pear.php.net/package/
*/
/**
* define include path constant
*/
if (!defined('XML_BEAUTIFIER_
define('XML_BEAUTIFIER_
}
/**
* element is empty
*/
define('XML_BEAUTIFIER_EMPTY', 0);
/**
* CData
*/
define('XML_BEAUTIFIER_CDATA', 1);
/**
* XML element
*/
define('XML_BEAUTIFIER_
/**
* processing instruction
*/
define('XML_BEAUTIFIER_PI', 4);
/**
* entity
*/
define('XML_BEAUTIFIER_ENTITY'
/**
* comment
*/
define('XML_BEAUTIFIER_
/**
* XML declaration
*/
define('XML_BEAUTIFIER_XML_
/**
* doctype declaration
*/
define('XML_BEAUTIFIER_DT_
/**
* cdata section
*/
define('XML_BEAUTIFIER_CDATA_
/**
* default
*/
define('XML_BEAUTIFIER_
/**
* overwrite the original file
*/
define('XML_BEAUTIFIER_
/**
* could not write to output file
*/
define('XML_BEAUTIFIER_ERROR_
/**
* could not load renderer
*/
define('XML_BEAUTIFIER_ERROR_
/**
* XML_Beautifier is a class that adds linebreaks and
* indentation to your XML files. It can be used on XML
* that looks ugly (e.g. any generated XML) to transform it
* to a nicely looking XML that can be read by humans.
*
* It removes unnecessary whitespace and adds indentation
* depending on the nesting level.
*
* It is able to treat tags, data, processing instructions
* comments, external entities and the XML prologue.
*
* XML_Beautifier is using XML_Beautifier_Tokenizer to parse an XML
* document with a SAX based parser and builds tokens of tags, comments,
* entities, data, etc.
* These tokens will be serialized and indented by a renderer
* with your indent string.
*
* Example 1: Formatting a file
* <code>
* require_once 'XML/Beautifier.php';
* $fmt = new XML_Beautifier();
* $result = $fmt->formatFileformatFile('
* </code>
*
* Example 2: Formatting a string
* <code>
* require_once 'XML/Beautifier.php';
* $xml = '<root><foo bar = "pear"/></root>';
* $fmt = new XML_Beautifier();
* $result = $fmt->formatString($xml);
* </code>
*
* @category XML
* @package XML_Beautifier
* @author Stephan Schmidt <schst@php.net>
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
* @license http://opensource.org/
* @version Release: 1.2.0
* @link http://pear.php.net/package/
*/
class XML_Beautifier
{
/**
* default options for the output format
* @var array
* @access private
*/
var $_defaultOptions = array(
"removeLineBreaks" => true,
"removeLeadingSpace" => true, // not implemented, yet
"indent" => " ",
"linebreak" => "\n",
"caseFolding" => false,
Информация о работе Методы хранения XML в реляционных базах данных