Create New XML File

Dim  tmpXml  As   New  Xml.XmlDocument
        
Dim  tmpNode  As  Xml.XmlNode
        
Dim  subNode  As  Xml.XmlNode
        
Dim  g_XmlDoc  As   New  Xml.XmlDocument

        
' 初始化XML
        tmpXml.LoadXml( " <?xml version=""1.0"" encoding=""GB2312""?><Root></Root> " )

        
' 添加用户信息节点"
        tmpNode  =  tmpXml.CreateNode(Xml.XmlNodeType.Element,  " User " Nothing )
        subNode 
=  tmpXml.CreateNode(Xml.XmlNodeType.Element,  " UserID " Nothing )
        subNode.InnerText 
=   " uid "
        subNode 
=  tmpXml.CreateNode(Xml.XmlNodeType.Element,  " UserName " Nothing )
        subNode.InnerText 
=   " uname "
        tmpNode.AppendChild(subNode)
        tmpXml.DocumentElement.AppendChild(tmpNode)

        
' 添加用户信息节点
        tmpNode  =  tmpXml.CreateNode(Xml.XmlNodeType.Element,  " Shop " Nothing )
        subNode 
=  tmpXml.CreateNode(Xml.XmlNodeType.Element,  " ShopID " Nothing )
        subNode.InnerText 
=   " shopid "
        tmpNode.AppendChild(subNode)
        subNode 
=  tmpXml.CreateNode(Xml.XmlNodeType.Element,  " ShopName " Nothing )
        subNode.InnerText 
=   " test "
        tmpNode.AppendChild(subNode)

        tmpXml.DocumentElement.AppendChild(tmpNode)
        tmpXml.Save(
" text.xml " )
        
MsgBox ( " ok " )

RESULT:
<? xml version="1.0" encoding="GB2312" ?>
< Root >
  
< User >
    
< UserName > uname </ UserName >
  
</ User >
  
< Shop >
    
< ShopID > shopid </ ShopID >
    
< ShopName > test </ ShopName >
  
</ Shop >
</ Root >

C#

Result

你可能感兴趣的:(create)