我想从数据库中读取三个字段type name info 将他们的值按照下面的逻辑写入xml文件中
<?xml version="1.0" encoding="utf-8" ?>
<diary>
  <type name="我的朋友" vlaue="我的朋友">
    <name name="宋岩岩">
      <info name="13713145200" />
      <info name="13155663258" />
      <info name="01062356986" />
    </name>
    <name name="龙建华">
      <info name="13713145200" />
      <info name="13696852168" />
      <info name="13892311682" />
    </name> 
  </type>
  
  <type name="我喜欢的网站" vlaue="我喜欢的网站">
    <name name="IT在中国">
      <info name="http://www.itzcn.com" />
      <info name="www.itzcn.com" />
      <info name="http;//itzcn.com" />
    </name>
    <name name="IT营">
      <info name="http://www.itying.net" />
      <info name="www.itying.net" />
      <info name="http://itying.net" />
    </name>
  </type>
</diary>
一时间逻辑搞不清楚,希望各位高手指点一下

解决方案 »

  1.   

    XmlDocument _Document = new XmlDocument();
                XmlNode _Node = _Document.CreateNode(XmlNodeType.Element, "diary","");
                _Document.AppendChild(_Node);            XmlNode _TypeNode = _Document.CreateNode(XmlNodeType.Element, "type","");
                XmlAttribute _NameAttrib =_Document.CreateAttribute("name");
                _NameAttrib.Value="我的朋友";
                XmlAttribute _ValueAttrib =_Document.CreateAttribute("vlaue");
                _ValueAttrib.Value="我的朋友";
                _TypeNode.Attributes.Append(_NameAttrib);
                _TypeNode.Attributes.Append(_ValueAttrib);            _Node.AppendChild(_TypeNode);
                XmlNode _NameNode = _Document.CreateNode(XmlNodeType.Element, "name", "");           
                XmlAttribute _SubNameAttrib = _Document.CreateAttribute("name");
                _SubNameAttrib.Value = "宋岩岩";
                _NameNode.Attributes.Append(_SubNameAttrib);            _TypeNode.AppendChild(_NameNode);
                XmlNode _InfoNode = _Document.CreateNode(XmlNodeType.Element, "info", "");
                XmlAttribute _InfoNameAttrib = _Document.CreateAttribute("name");
                _InfoNameAttrib.Value = "1234567890123";
                _InfoNode.Attributes.Append(_InfoNameAttrib);            _NameNode.AppendChild(_InfoNode);            _Document.Save(@"C:\1.xml");
    循环自己写把