VML绘图板⑤浏览--view.php

 更新时间:2016年11月25日 16:56  点击:2120
<html>
<xmlns:v="urn:schemas-microsoft-com:vml" />
<head>
<meta http-equiv="Content-type" content="text/html; charset=gb2312">
<title>VML绘图板</title>
<style>
v:* { behavior: url(#default#VML); }
td { font-size:9pt; }
</style>
</head>
<script src="XMLtool.js"></script>
<script>
// 钩子函数,用于清除代码显示
function hooke() {
    code.innerText = "";
}
// 从服务器获取XML文档。服务器将返回vml文档,可以根据参数v简单的用readfile函数
function loadXML(v)
{
    var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHTTP.open("GET","server.php?info="+v,false);
    xmlHTTP.setRequestHeader("Contrn-type","text/xml");
    xmlHTTP.setRequestHeader("Contrn-charset","gb2312");
    xmlHTTP.send(v);
    view.innerHTML = xmlHTTP.responseText;
    hooke();
    if(xmlHTTP.responseText.indexOf("Error:")!=-1) {
    alert(xmlHTTP.responseText);
    }
}
// 以下函数用于与vml文档交互
function cursor() {}
function mouse_down() {}
function mouse_up() {}
function setOverColor() {}
function setOutColor() {}
function deleteNode() {}
</script>
<body onLoad="loadXML(1)">
<table>
<tr>
    <td>作品展示</td>
</tr>
<tr>
    <td id="view"></td>
</tr>
<tr>
    <td>
<?php
// 变量num为保存的vml文档总数,这里仅简单的指定。请根据实际的组织调整

php中对xml读取的相关函数的介绍:

--------------------------------------------------------------------------------

对象 XML解析函数 描述
元素 xml_set_element_handler() 元素的开始和结束
字符数据 xml_set_character_data_handler() 字符数据的开始
外部实体 xml_set_external_entity_ref_handler() 外部实体出现
未解析外部实体 xml_set_unparsed_entity_decl_handler() 未解析的外部实体出现
处理指令 xml_set_processing_instruction_handler() 处理指令的出现
记法声明 xml_set_notation_decl_handler() 记法声明的出现
默认 xml_set_default_handler() 其它没有指定处理函数的事件

--------------------------------------------------------------------------------

下面就给大家举一个小小的例子用parser函数来读取xml数据:



<?php
$parser = xml_parser_create(); //创建一个parser编辑器
xml_set_element_handler($parser, "startElement", "endElement");//设立标签触发时的相应函数 这里分别为startElement和endElenment
xml_set_character_data_handler($parser, "characterData");//设立数据读取时的相应函数
$xml_file="1.xml";//指定所要读取的xml文件,可以是url
$filehandler = fopen($xml_file, "r");//打开文件




while ($data = fread($filehandler, 4096))
{
xml_parse($parser, $data, feof($filehandler));
}//每次取出4096个字节进行处理

fclose($filehandler);
xml_parser_free($parser);//关闭和释放parser解析器


$name=false;
$position=false;
function startElement($parser_instance, $element_name, $attrs) //起始标签事件的函数
{
global $name,$position;
if($element_name=="NAME")
{
$name=true;
$position=false;
echo "名字:";
}
if($element_name=="POSITION")
{$name=false;
$position=true;
echo "职位:";
}
}

function characterData($parser_instance, $xml_data) //读取数据时的函数
{
global $name,$position;
if($position)
echo $xml_data."<br>";
if($name)
echo $xml_data."<br>";
}

function endElement($parser_instance, $element_name) //结束标签事件的函数
{
global $name,$position;
$name=false;
$position=false;
}

?>

xml文件代码如下:



<?xml version="1.0"?>
<employees>
<employee>
<name>张三</name>
<position age="45">经理</position>
</employee>
<employees>
<employee>
<name>李四</name>
<position age="45">助理</position>
</employee>
</employees>

这个程序的结果如下:

--------------------------------------------------------------------------------

名字:张三 职位:经理
名字:李四 职位:助理

example2.php
<?php
include_once("XML/sql2xml.php");
$sql2xmlclass = new xml_sql2xml("mysql://username:password@localhost/xmltest");
$xmlstring = $sql2xmlclass->getxml("select * from bands left join albums on bands.id = bandsID");
?>

输出结果
$xmlstring = '
<?xml version="1.0"?>
    <root>
        <result>
       <row>
           <id>1</id>
           <name>The Blabbers</name>
           <birth_year>1998</birth_year>
           <birth_place>London</birth_place>
           <genre>Rock'n'Roll</genre>
           <row>
          <id>1</id>
          <bandsID>1</bandsID>
          <title>BlaBla</title>
          <year>1998</year>
          <comment>Their first one</comment>
           </row>
           <row>
          <id>2</id>
          <bandsID>1</bandsID>
<?php
/**
* Topic: Create and parse XML files using PHP DOM-XML
* Source: http://www.php.net/domxml
* Reference: http://www.zugeschaut-und-mitgebaut.de/php/extension.domxml.html
* Author: urs@circle.ch, 16-1-2001
*
*/
// 使用PHP DOM-XML创建和解析XML文件
//创建XML文档对象;以后的处理过程将在此基础上进行
$doc = new_xmldoc("1.0" );
//创建根节点,并设置一个属性
$root = $doc->add_root("faq" );
$root->setattr("page", "32" );
//子节点
$one = $root->new_child("question", "");
//为子节点设置属性
$one->setattr("number", "1");
//question也创建子节点,并且给它赋值
$one->new_child("text", "1. Where to get libxml-2.0.0?");
$one->new_child("answer", "You can download the latest
release of libxml either as a source archive or
RPM package from http://www.xmlsoft.org.
The current version is libxml2-2.2.1." );
$two = $root->new_child("question", "" );
$two->setattr("number", "2");
$two->new_child("text", "2. How to configure PHP4?" );
// 创建一个不直接赋值的节点
$twoone = $two->new_child("answer", "");
// 然后给它单独赋值
$twoone->set_content("DIR is the libxml install directory
(if you just use --with-dom it defaults
to /usr), I needed to use --with-dom=/usr/local" );
$three = $root->new_child("question", "" );
$three->setattr("number", "7" );
$three->new_child("text", "7. How to use DOM XML function ?" );
$three->new_child("answer", "Read this document source for
a simple example." );
//输出到Browser
print("<pre>".htmlspecialchars($doc->dumpmem() )."</pre>" );
// write to file
//写回到文件
$fp = fopen("test_dom.xml", "w+" );
fwrite($fp, $doc->dumpmem(), strlen($doc->dumpmem() ));
fclose($fp);
// ------------------------------------------------------
资源
***************
* VMLgraph.xml
***************
<?xml version="1.0" encoding="GB2312" ?>
<root xmlns:v="urn:schemas-microsoft-com:vml">
<toolbar id="1">
    <v:group ID="cut" style="width:24; height:24; cursor:hand" coordsize="30,30" title="裁剪" onClick="select(this)">
     <v:rect style="width:30; height:30;" fillcolor="#ffffff" strokecolor="#000000" strokeweight="1" />
     <v:line from="11,4" to="20,26" />
     <v:arc style="left:6; top:12; width:8; height:12;" startangle="180" endangle="400">
    <v:fill opacity="0" />
     </v:arc>
     <v:line from="19,4" to="10,26" />
     <v:arc style="left:16; top:12; width:8; height:12;" startangle="0" endangle="180">
    <v:fill opacity="0" />
     </v:arc>
    </v:group>
</toolbar>
<toolbar id="2">
     <v:group style="width:24; height:24; cursor:hand" coordsize="30,30" title="正常" onClick="select(this)">
    <v:rect style="width:30; height:30;" fillcolor="#ffffff" strokecolor="#000000" strokeweight="1" />
    <v:shape style="width:30; height:30;" strokecolor="#000000">
     <v:path v="m 9,5 l 9,20, 12,16 17,25 19,23 15,15 19,15 x e" />
[!--infotagslink--]

相关文章