Do I need to define all the elements in an XML Object?
var block = (from query in data.Descendants("block")
where query.Element("itemid").Value == argID.ToString()
select new Block
{
Name = (string)query.Element("name"),
ItemID = (int)query.Element("itemid"),
Description = (string)query.Element("description")
}
).Single();
Do I need to define all the fields from my XML document? Or is there an easier way since I'm defining the Block already.
public class Block
{
int itemid;
string name;
string description;
public string Name
{
get { return name; }
set { name = value; }
}
public int Item开发者_如何学PythonID
{
get { return itemid; }
set { itemid = value; }
}
public string Description
{
get { return description; }
set { description = value; }
}
public string Price
{
get { return price; }
set { price= value; }
}
}
If you mean do you have to pull everything from the xml file into your object, the answer is no.
You can populate which ever content you want from the xml into your model.
With regard to your object, whether you have to populate everything in your destination object the answer is no also, unless you have rules on your domain objects that must be satisfied, but that code's in your control.
精彩评论