Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Adding the Parent id to Serialization as Object class

$
0
0
I have the following XML file which I am using the VSC#(windows forms) code to save it as a class:

   
<Steps >  <Step id ="1" Name="S1">    <Step id ="2" Name="S11">      <Step id ="3" Name="S111" />      <Step id ="4" Name="S112" />        <Step id ="5" Name="S1121" />    </Step >    <Step id ="6" Name="S12" />  </Step ></Steps >


The code I wrote as:

   
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]   
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]   
public partial class Steps   
{     
   [System.Xml.Serialization.XmlElementAttribute("Step")]       public List<Step> Step { get; set; }   
}   
[System.SerializableAttribute()]   
[System.ComponentModel.DesignerCategoryAttribute("code")]   
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]   
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]   
public partial class Step   
{       [System.Xml.Serialization.XmlElementAttribute("Step")]     public List<Step> Step1 { get; set; }     [System.Xml.Serialization.XmlAttributeAttribute()]       
    public string name { get; set; }   
    [System.Xml.Serialization.XmlAttributeAttribute()]       
    public string id { get; set; }       [System.Xml.Serialization.XmlAttributeAttribute()]       
    public string ParentID { get; set; }   
}


I have two questions:

 1. How can I get the `ParentID` into the child field for
    children?(there would be only `null` for node with `id=1`, otherwise
    each child has its parents id)
 2. The second question is that after coding in object class, how could
    I insert a desired child with giving the id name? For example, I
    would like to insert a child with `id=4C`  and `name=S112C` after
    node with `id=4`?

Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>