为什么用了simplexml,还要用dom? 改了一下,直接用simplexml
xml文件添加了一个root根结点<?php
$xmlFile="<?xml version='1.0' encoding='utf-8' ?>
<root>
<Config Domain='octon.cn' 
Orig='ppchat'
Svc='tcp:192.168.10.23:4002' 
Req='http://192.168.10.23:4000/service/irouter' 
TimeOut = '300000'
AutoReply = '0'
Dest = 'ichat'>
<Filter Domain='octon.cn'
    Group='CHAT'
    Type='*'
    Name='*'
    Origination='*'
    Destination='ppchat' >
    <Body/>
</Filter>
</Config>
</root>";$doc = simplexml_load_string($xmlFile);
xml2SQL($doc);function xml2SQL($nodeName)
{
foreach($nodeName as $k=>$v)
{
echo $k.'<br>';
}

foreach($nodeName->attributes() as $key => $value)
{
   
   //echo $key,'="',$value,"\"\n";
}foreach ($nodeName->Children() as $nodeName)
{
xml2SQL($nodeName);
}
}
?>

解决方案 »

  1.   

    <?php
    $sid=$_GET[sid];
    $sid="ppchat";
    $xmlFile="<?xml version='1.0' encoding='utf-8' ?>
    <Config Domain='octon.cn' 
    Orig='ppchat'
     Svc='tcp:192.168.10.23:4002' 
     Req='http://192.168.10.23:4000/service/irouter' 
     TimeOut = '300000'
     AutoReply = '0'
     Dest = 'ichat'>
    <Filter Domain='octon.cn'
        Group='CHAT'
        Type='*'
        Name='*'
        Origination='*'
        Destination='ppchat' >
        <Body Name='wanzhenhua' sex='male' age='22' city='shanghai'/>
    </Filter>
    </Config>";
    /**/
    // header("Content-Type: text/xml; charset=utf-8"); 
    // $xmlFile=$_POST[xmlFile];
    // $xmlFile=str_replace("\\", "",$xmlFile);
    $doc = simplexml_load_string($xmlFile);
    //create config table
    xml2SQL($doc);function xml2SQL($node)
    {
    $fields=null;
    $values=null;
    $isEcho=false;
    $strSQL="insert into ";
    $tableName=null;
    $nodeName=null;
    global $sid; foreach($node->attributes() as $key => $value)
    {
       //组织SQL语句,入库
       $fields.=$key.",";
       $values.="'".$value."'".",";
       $isEcho = true;
    }

    if($isEcho)

     $nodeName=$node->node_name; 
     $tableName="Config_".$sid."_".$nodeName;
     $fields = rtrim($fields, " \t,");
     $values = rtrim($values, " \t,");
     $strSQL.=$tableName." (".$fields.") values (".$values.")";
     echo $strSQL."<br>";
    }

    foreach ($node->Children() as $node)
    {
    xml2SQL($node);
    }
    }
    ?>
    这段代码得到的结果是:
    insert into Config_ppchat_  ...
    insert into Config_ppchat_   ...
    insert into Config_ppchat_ ...
    而我想要的结果是:
    insert into Config_ppchat_Config ...
    insert into Config_ppchat_Filter ...
    insert into Config_ppchat_Body ...
    这个怎么做呢?最好是不能加root结点
    不胜感激啊!!!
      

  2.   

    <?php
    $sid=$_GET[sid];
    $sid="ppchat";
    $xmlFile="<?xml version='1.0' encoding='utf-8' ?>
    <Config Domain='octon.cn' 
    Orig='ppchat'
     Svc='tcp:192.168.10.23:4002' 
     Req='http://192.168.10.23:4000/service/irouter' 
     TimeOut = '300000'
     AutoReply = '0'
     Dest = 'ichat'>
    <Filter Domain='octon.cn'
        Group='CHAT'
        Type='*'
        Name='*'
        Origination='*'
        Destination='ppchat' >
        <Body Name='wanzhenhua' sex='male' age='22' city='shanghai'/>
    </Filter>
    </Config>";
    /**/
    //header("Content-Type: text/xml; charset=utf-8"); 
    //$xmlFile=$_POST[xmlFile];
    //$xmlFile=str_replace("\\", "",$xmlFile);$dom = new DOMDocument('1.0');
    $dom->loadXML($xmlFile);
    $root = $dom->documentElement;xml2SQL($root);
    function xml2SQL($node)
    {
    $fields=null;
    $values=null;
    $isEcho=false;
    $strSQL="insert into ";
    $tableName=null;
    $nodeName=null;
    global $sid;foreach($node->attributes as $key => $attribute)
    {
       //组织SQL语句,入库
       $fields.=$key.",";
       $values.="'".$attribute->nodeValue."'".",";
       $isEcho = true;
    }if($isEcho)
    {  $nodeName= $node->nodeName;
     $tableName="Config_".$sid."_".$nodeName;
     $fields = rtrim($fields, " \t,");
     $values = rtrim($values, " \t,");
     $strSQL.=$tableName." (".$fields.") values (".$values.")";
     echo $strSQL."<br/>";}foreach ($node->childNodes as $childNode)
    {
    if ($childNode->nodeName != '#text')
    xml2SQL($childNode);
    }
    }
    ?>
      

  3.   

    body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    scrollbar-face-color:#f4f4f4;
    scrollbar-highlight-color: #DDDDDD;
    scrollbar-3dlight-color: #ffffff;
    scrollbar-shadow-color: #CCCCCC;
    scrollbar-darkshadow-color: #EEEEEE;
    scrollbar-track-color: #EFEFEF;
    scrollbar-arrow-color: #ffffff;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: normal;
    color: #666666;
    }
    a:link {
    text-decoration: underline;
    color: #003300;
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: bold;
    }
    a:visited {
    font-size: 12px;
    text-decoration: none;
    color: #006699;
    }
    a:hover {
    font-size: 12px;
    text-decoration: underline;
    color: #FF6600;
    font-weight: bold;
    }
    a:active {
    text-decoration: underline;
    color: #003366;
    }.table {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    color: #333333;
    height: 25px;
    }
    #select{
    background-color: #f9f9f9;
    }
    .button{
    font-family: tahoma, verdana, sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #FFFFFF;
    border: 1px solid #003300;
    padding: 0px;
    background-color: #359D77;
    cursor:hand;
    width:80px
    }
    #select{
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: bold;}
    .font {
    font-family: tahoma, verdana, sans-serif;
    font-size: 11px;
    color: #333333;
    }
    .font_b {
    font-family: tahoma, verdana, sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #003300;
    }
    .font_b2 {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #333300;
    text-decoration: none;
    }
    .font_t {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #000000;

    }
    .font_ct {
    font-family: tahoma,verdana,sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #003300;
    text-decoration: underline;
    }
    .font_ct_s {
    font-family: tahoma,verdana,sans-serif;
    font-size: 10px;
    font-weight: bold;
    color: #5B833A;}
    .font_w {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: normal;
    color: #FFFFFF;
    }
    .font_b_w {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #FFFFFF;
    }
    .line {
    color: #000000;
    border: 1px dashed #006699;
    }
    .font_s {
    font-family: tahoma,verdana,sans-serif;
    font-size: 10px;
    color: #003300;
    }
    .input_2 {
    background-color: #f2f2f2;
    }
    .font_num {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #FF6600;
    }
    .font_table {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #003333;
    background-color: #CBE9CB;
    border: 2px solid #006600;
    margin: 0px;
    padding: 1px;
    }
    .font_tt {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: normal;
    color: #003333;
    text-decoration: underline;
    }
    .select {
    font-family: tahoma, verdana, sans-serif;
    font-size: 12px;
    color: #003300;
    background-color: #E9F7E6;
    font-weight: bold;
    }
    .right {
    font-family: tahoma,verdana,sans-serif;
    font-size: 10px;
    font-weight: bold;
    color: #003300;}
    .right_b {
    font-family: tahoma,verdana,sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #003300;
    }
    .dot {
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #003300;
    }
    .input_red {
    background-color: #FFCC99;
    }
    .inp {
    background-color: #FFCC00;
    }
    .inputs_red {
    font-family: tahoma,verdana,sans-serif;
    font-size: 14px;
    background-image: url(../img/css_bg.gif);
    border: 2px solid #5B833A;
    height: 25px;
    padding: 3px;}
    .inputs_area {
    font-family: tahoma,verdana,sans-serif;
    font-size: 14px;
    background-image: url(../img/css_bg.gif);
    border: 2px solid #5B833A;
    padding: 3px;
    }
    .font {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: normal;
    color: #333300;
    }
    .inputs {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: normal;
    color: #003300;
    border: 1px solid #A7A7A7;
    width: 160px;
    height: 18px;
    background-color: #FFFFFF;
    }
    .table_head {
    background-image: url(../img/table_css.gif);
    }
    .table_head2 {
    background-image: url(../img/table_css2.gif);
    }.tophead {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: normal;
    color: #000000;
    }
    .ta{
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    background-image: url(../img/css_bg.gif);
    border: 1px solid #5B833A;
    padding: 1px;
    width: 180px;
    }
    .ta_2{
    width: 300px;
    height:80px;
    font-family: tahoma,verdana,sans-serif;
    font-size: 12px;
    background-image: url(../img/css_bg.gif);
    border: 1px solid #5B833A;
    padding: 1px;
    }
      

  4.   

    /*验证码*/
    /* Copyright all(c) 2005 ZhongFeng, http://blog.csdn.net/SW515 */
     public class ValidateCode : System.Web.UI.Page
     {
      private void Page_Load(object sender, System.EventArgs e)
      {
       this.CreateCheckCodeImage(GenerateCheckCode());
      }  #region Web 窗体设计器生成的代码
      override protected void OnInit(EventArgs e)
      {
       //
       // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
       //
       InitializeComponent();
       base.OnInit(e);
      }
      
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {    
       this.Load += new System.EventHandler(this.Page_Load);
      }
      #endregion  private string GenerateCheckCode()
      {
       int number;
       char code;
       string checkCode = String.Empty;   System.Random random = new Random();   for(int i=0; i<5; i++)
       {
        number = random.Next();    if(number % 2 == 0)
         code = (char)('0' + (char)(number % 10));
        else
         code = (char)('A' + (char)(number % 26));    checkCode += code.ToString();
       }   Response.Cookies.Add(new HttpCookie("CheckCode", checkCode));   return checkCode;
      }  private void CreateCheckCodeImage(string checkCode)
      {
       if(checkCode == null || checkCode.Trim() == String.Empty)
        return;   System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);
       Graphics g = Graphics.FromImage(image);   try
       {
        //生成随机生成器
        Random random = new Random();    //清空图片背景色
        g.Clear(Color.White);    //画图片的背景噪音线
        for(int i=0; i<25; i++)
        {
         int x1 = random.Next(image.Width);
         int x2 = random.Next(image.Width);
         int y1 = random.Next(image.Height);
         int y2 = random.Next(image.Height);     g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
        }    Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
        System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
        g.DrawString(checkCode, font, brush, 2, 2);    //画图片的前景噪音点
        for(int i=0; i<100; i++)
        {
         int x = random.Next(image.Width);
         int y = random.Next(image.Height);     image.SetPixel(x, y, Color.FromArgb(random.Next()));
        }    //画图片的边框线
        g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);    System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
        Response.ClearContent();
        Response.ContentType = "image/Gif";
        Response.BinaryWrite(ms.ToArray());
       }
       finally
       {
        g.Dispose();
        image.Dispose();
       }
      }
     }
      假如以上验证码生成器页面名为:CheckCode.aspx,那么在登录页面中使用“<IMG>” 这个 HTML 元素来显示生成的验证码图片:<IMG src="CheckCode.aspx">
      在登录页面的登录按钮的处理事件中使用以下代码判断验证码:
      private void btnLogin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
      {
       if(Request.Cookies["CheckCode"] == null)
       {
        lblMessage.Text = "您的浏览器设置已被禁用 Cookies,您必须设置浏览器允许使用 Cookies 选项后才能使用本系统。";
        lblMessage.Visible = true;
        return;
       }    if(String.Compare(Request.Cookies["CheckCode"].Value, txtCheckCode.Text, true) != 0)
       {
        lblMessage.Text = "验证码错误,请输入正确的验证码。";
        lblMessage.Visible = true;
        return;
       }        /*****  其他代码  *****/  }
      

  5.   

    function GetElementPos(id)
    {
        var left = 0;
        var top = 0;
        var obj = document.getElementById(id);
        if(obj.x)
        {
            left= obj.x;
            top = obj.y;
        }
        else if(obj.offsetParent)
        {
            while(obj.offsetParent)
            {
                left += obj.offsetLeft;
                top  += obj.offsetTop;
                obj = obj.offsetParent;
            } 
        }
     /*    alert("x:"+top+",y:"+left);
                  var ary = new Array();
        //            ary[0] = left;
        //            ary[1] = top;
        //            return ary;*/
    }
      

  6.   

    当活动元素从当前控件对象变为父文档或者其他控件对象时触发 ondrag       当进行拖拉操作时在源控件对象上持续触发 ondragend    当用户在拖拉操作结束后释放鼠标时在源控件对象上触发 ondragenter  当用户拖拉控件对象到一个合法拖拉目标时在目标元素上触发 ondragleave  当用户在拖拉操作过程中将鼠标移出合法拖拉目标时在目标控件对象上触发 ondragover  当用拖拉控件对象划过合法拖拉目标时持续在目标元素上触发 ondragstart 当用户开始拖拉文本选中区或选中控件对象时在源控件对象上触发 onfocus     当控件对象获得焦点时触发 onkeydown   当用户按下键盘按键时触发 onkeypress  当用户按下字面按键时触发