How to add xmlnamespace to a xmldocument

前端 未结 3 973
终归单人心
终归单人心 2020-12-03 21:47

Im trying to create a xml the should look like this




        
3条回答
  •  天命终不由人
    2020-12-03 21:55

    XmlDocument xmlDocSPack = new XmlDocument();
    XmlNode xmldocNode = xmlDocSPack.CreateXmlDeclaration("1.0", "", null);
    xmlDocSPack.AppendChild(xmldocNode);
    
    XmlElement LiftsMainNode = xmlDocSPack.CreateElement("Lifts");
    LiftsMainNode.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    
    xmlDocSPack.AppendChild(LiftsMainNode);
    xmlDocSPack.Save("SPack"+DateTime.Now.Year + ".xml");
    

    Output :

    
    
    

提交回复
热议问题