zoukankan      html  css  js  c++  java
  • C# 创建xml

    <?xml version="1.0" encoding="UTF-8"?>
    <swUpgrade xmlns="http://www.3gpp.org/ftp/specs/archive/32_series/32.645#utranNrm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.3gpp.org/ftp/specs/archive/32_series/32.645#utranNrm swUpgrade.xsd">
      <contentBlock>
        <compatibleALDs>
          <compatibilityInformation>
            <vendorCode>VR</vendorCode>
            <aldType>aldType</aldType>
            <productNumber>productNumber</productNumber>
            <swVersion>swVersion</swVersion>
            <hwVersion>hwVersion</hwVersion>
          </compatibilityInformation>
        </compatibleALDs>
        <sw>VG9uZ1l1MTRSQ1UyLjEuMAAAAAAAAAAAAAAAAAAAAACYCwAgiSEACG03</sw>
      </contentBlock>
    </swUpgrade>
     private void CreateXML(string xmlFilePath)
            {
                string xmlnsAttr= "http://www.3gpp.org/ftp/specs/archive/32_series/32.645#utranNrm";
                string xmlnsXsiAttr = "http://www.w3.org/2001/XMLSchema-instance";
                string xsiSchemaLocAttr = "http://www.3gpp.org/ftp/specs/archive/32_series/32.645#utranNrm swUpgrade.xsd";
    
                XmlDocument xmlDoc = new XmlDocument();
                //加入XML的声明段落
                xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null));
    
               // swUpgrade
                XmlElement swUpgradeElement = xmlDoc.CreateElement("swUpgrade");
                swUpgradeElement.SetAttribute("xmlns", xmlnsAttr);
                swUpgradeElement.SetAttribute("xmlns:xsi", xmlnsXsiAttr);
                swUpgradeElement.SetAttribute("xsi:schemaLocation", xsiSchemaLocAttr);
                xmlDoc.AppendChild(swUpgradeElement);
    
                    //contentBlock
                    XmlNode contentBlockNode = xmlDoc.CreateElement("contentBlock");
    
                        //compatibleALDs
                        XmlNode compatibeALDsNode = xmlDoc.CreateElement("compatibleALDs");
    
                            //compatibilityInformation
                            XmlNode informationNode = xmlDoc.CreateElement("compatibilityInformation");
                                XmlElement vendorCodeElement = xmlDoc.CreateElement("vendorCode");
                                vendorCodeElement.InnerText = "VR";
                                XmlElement aldTypeElement = xmlDoc.CreateElement("aldType");
                                aldTypeElement.InnerText = "aldType";
                                XmlElement productNumberElement = xmlDoc.CreateElement("productNumber");
                                productNumberElement.InnerText = "productNumber";
                                XmlElement swVersionElement = xmlDoc.CreateElement("swVersion");
                                swVersionElement.InnerText = "swVersion";
                                XmlElement hwVersionElement = xmlDoc.CreateElement("hwVersion");
                                hwVersionElement.InnerText = "hwVersion";
    
                               informationNode.AppendChild(vendorCodeElement);
                               informationNode.AppendChild(aldTypeElement);
                               informationNode.AppendChild(productNumberElement);
                               informationNode.AppendChild(swVersionElement);
                               informationNode.AppendChild(hwVersionElement);
                       compatibeALDsNode.AppendChild(informationNode);
    
                   contentBlockNode.AppendChild(compatibeALDsNode);
    
                   XmlNode swNode = xmlDoc.CreateElement("sw"); ;
                   swNode.InnerText = "VG9uZ1l1MTRSQ1UyLjEuMAAAAAAAAAAAAAAAAAAAAACYCwAgiSEACG03";
    
                   contentBlockNode.AppendChild(swNode);
                swUpgradeElement.AppendChild(contentBlockNode);
                xmlDoc.Save(@"d:	est.xml");
    
            }
  • 相关阅读:
    Nginx如何配置Http、Https、WS、WSS?
    关于MySQL日志,我与阿里P9都聊了些啥?
    一文搞懂MySQL体系架构!!
    在业务高峰期拔掉服务器电源是一种怎样的体验?
    千万不要轻易尝试“熊猫烧香”,这不,我后悔了!
    从小白程序员到大厂高级技术专家我看过哪些书籍?
    聊一聊我在 B 站自学 Java 的经历吧
    计算机网络的 89 个核心概念
    MQTT 协议是个啥?这篇文章告诉你!
    1.5w字 + 24张图肝翻 TCP。
  • 原文地址:https://www.cnblogs.com/ike_li/p/5881361.html
Copyright © 2011-2022 走看看