how to add xml schema

90 views Asked by At

I have a XML schema xsd which i converted into a cs file using Xsd2Code tool in visual studio,

What I am currently doing is, // ignore syntax please as hand written

Public Method_1()
{
Fruits f = new Fruits();
f.Name = "Mangoes";

Foreach (DataRow row in DataTable)  //assume i am getting rows from database
{
      FruitsCrate fc = new FruitsCrate();
      fc.Id = 2;
      fc..... etc

      f.FruitsCrate.add(fc);  // as fruitCrate is a child node of fruit   
}

Foreach (DataRow row in DataTable)
{
      FruitBasket fb = new FruitBasket();
      fb.id = 2;
      fb....   etc

      f.FruitBaskets.add(fb);  // as fruit basket is child node
}

//a lot of more foreach just like above
}

Now problem is I want to put foreach statements in a different methods so I am not sure how can i add different childNodes to parent node,

What I am trying to do is,

Public Method_1()   //hand written code so syntax might not be right
{
   Fruits f = new Fruits();
   f = Method-2();   // ???????????????
   f = Method-3(); 
   f = Method-4(); //...........  won't f value will be reset each time
}

public Fruits Method_2(Fruits f)
{
    foreach(dataRow row in DataTable)
    {
        FruitCrate fc = new FruitCrate();
        fc.propertyA = "aaaa"; etc...

        f.FruitsCrate.add(fc);
    }
   return f;
}

2nd way of coding is hand written and I don't think will work or is even possible way

0

There are 0 answers