½«Êý×éת»¯ÎªXMLÊý¾Ý
/* Author: ÑîÓî yangyu@sina.cn */
/*
Ó÷¨Ê¾Àý£º
$cls_xml = new cls_xml();
if ($array){
$cls_xml->array2xml($array);
echo $cls_xml->getXml();
}else{
echo '';
}
*/
class cls_xml{
var $xml;
public function array2xml($array,$encoding='gb2312'){
$this->xml = '<?xml version="1.0" encoding="'.$encoding.'"?><list>';
$this->xml.= $this->_array2xml($array).'</list>';
}
public function getXml(){
return $this->xml;
}
public function _array2xml($array){
$xml = '';
foreach($array as $key => $val){
is_numeric($key) && $key = "item id=\"$key\"";
$xml. = "<$key>";
$xml. = is_array($val) ? $this->_array2xml($val) : $this->_cdata($val);
list($key,) = explode(' ',$key);
Ïà¹ØÎĵµ£º
1£©DOM£¨JAXP Crimson½âÎöÆ÷£©
DOMÊÇÓÃÓëƽ̨ºÍÓïÑÔÎ޹صķ½Ê½±íʾXMLÎĵµµÄ¹Ù·½W3C±ê×¼¡£DOMÊÇÒÔ²ã´Î½á¹¹×éÖ¯µÄ½Úµã»òÐÅϢƬ¶ÏµÄ¼¯ºÏ¡£Õâ¸ö²ã´Î½á¹¹ÔÊÐí¿ª·¢ÈËÔ±ÔÚÊ÷ÖÐÑ°ÕÒÌض¨ÐÅÏ¢¡£·ÖÎö¸Ã½á¹¹Í¨³£ÐèÒª¼ÓÔØÕû¸öÎĵµºÍ¹¹Ôì²ã´Î½á¹¹£¬È»ºó²ÅÄÜ×öÈκι¤×÷¡£ÓÉÓÚËüÊÇ»ùÓÚÐÅÏ¢²ã´ÎµÄ£¬Òò¶ ......
C#
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/Config/User_yhlx_Jb.xml"));
DataView dv = ds.Tables[0].DefaultView;
//dv.RowFilter = "State=0";
this.DropDownList1.DataSource = dv;
this.DropDownList1.DataTextField = "text";
this ......
XML½âÎöÆ÷µÄ×÷ÓãºÎªÓ¦ÓóÌÐò´ÓXMLÎļþÖнâÎö³öËùÐèÒªµÄÊý¾Ý¡£
ÏÂÃæͨ¹ýÒ»¸öÀý×Ó£¬À´Á˽⣬ÈçºÎÓÃXML½âÎöÆ÷£¬À´½âÎöÒ»¸öXMLÎļþÖеÄÊý¾Ý¡£
1¡¢Types.xml£¨ÏÔʾ¼ªËûµÄÀà±ð£©
<?xml version="1.0" encoding="UTF-8"?>
<types>
<name>µç¼ªËû
<music>ÍæÒ¡¹ö</music>
</name>
......
1£©XmlÎĵµÊ¾Àý£¨xmlsample.xml£©£º
Code
<?xml version="1.0" encoding="iso-8859-1" ?>
<music>
<song title="Oh,girl">
<artist>The Chi-lites</artist>
<genre>Soul</genre>
&nb ......
var createXML = function (str) {
if (typeof DOMParser !== "undefined") {
return (new DOMParser()).parsefromString(str, "application/xml");
}else if (typeof ActiveXObject != "undefined") {
if (typeof arguments.callee.activeXString !== "string" ......