zoukankan      html  css  js  c++  java
  • How to generate xml through c# code for below xml sample

    you have to use XmlBuilder object to build XML file/string

    e.g.

    /////XML
    <?xml version="1.0" encoding="utf-8"?>
    <children>
       
    <!--Children below...-->
       
    <child age="1" referenceNumber="ref-1">child &amp; content #1</child>
       
    <child age="2" referenceNumber="ref-2">child &amp; content #2</child>
       
    <child age="3" referenceNumber="ref-3">child &amp; content #3</child>
       
    <child age="4" referenceNumber="ref-4">child &amp; content #4</child>
       
    <child age="5" referenceNumber="ref-5">child &amp; content #5</child>
       
    <child age="6" referenceNumber="ref-6">child &amp; content #6</child>
       
    <child age="7" referenceNumber="ref-7">child &amp; content #7</child>
       
    <child age="8" referenceNumber="ref-8">child &amp; content #8</child>
       
    <child age="9" referenceNumber="ref-9">child &amp; content #9</child>
    </children>



    C
    # Code



    XmlDocument xml =newXmlDocument();
    XmlElement root = xml.CreateElement("children");
    xml
    .AppendChild(root);

    XmlComment comment = xml.CreateComment("Children below...");
    root
    .AppendChild(comment);

    for(int i =1; i <10; i++)
    {
           
    XmlElement child = xml.CreateElement("child");
            child
    .SetAttribute("age", i.ToString());
            child
    .SetAttribute("referenceNumber","ref-"+ i);
            child
    .InnerText="child & content #"+ i;
            root
    .AppendChild(child);
    }

    string s = xml.OuterXml;
    plz mark asANSWERif it helps u
  • 相关阅读:
    何为受控组件(controlled component)
    (组件的)状态(state)和属性(props)之间有何不同
    类组件(Class component)和函数式组件(Functional component)之间有何不同
    [翻译] FSLineChart
    [翻译] DXPopover
    [翻译] LTInfiniteScrollView
    设计模式
    [翻译] LLSimpleCamera
    [翻译] VLDContextSheet
    将Model对象转换成json文本或者json二进制文件
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/2436130.html
Copyright © 2011-2022 走看看