I have the following XML file with "page" nodes which I want to read into "PageItem" objects in my application. Most of the XML nodes I save as string/int/DataTime property which works fine.
But what is the best way to store the XML child nodes of the "content" node in a property of a PageItem object so that I can parse it later within the application? Should I store it as a string and later read in the string as XML or is there a more efficient way to store the XML child nodes as a property?
<?xml version="1.0" encoding="utf-8" ?>
<pages>
<page>
<id>1</id>
<whenCreated>2007-01-19T00:00:00</whenCreated>
<itemOwner>edward</itemOwner>
<publishStatus>published</publishStatus>
<correctionOfId>0</correctionOfId>
<idCode>contactData</idCode>
<menu>mainMenu</menu>
<title>Contact Data</title>
<description>This is contact data page.</description>
<accessGroups>loggedInUsers,loggedOutUsers</accessGroups>
<displayOrder>10</displayOrder>
<content>
<form idcode="customers" query="limit 5; category=internal"/>
<form idcode="customersDetail" query="limit 10; category=internal"/>
</content>
</page>
<page>
<id>2</id>
<whenCreated>2007-01-29T00:00:00</whenCreated>
<itemOwner>edward</itemOwner>
...
I read this XML file into PageItem objects:
public class PageItem : Item
{
public string IdCode { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Menu { get; set; }
public string AccessGroups { get; set; }
public int DisplayOrder { get; set; }
public List<XmlNode> Content { get; set; } //PSEUDO-CODE
with this code:
var pageItems = from pageItem in xmlDoc.Descendants("page")
orderby (int)pageItem.Element("displayOrder")
select new Models.PageItem
{
Id = (int)pageItem.Element("id"),
WhenCreated = (DateTime)pageItem.Element("whenCreated"),
ItemOwner = pageItem.Element("itemOwner").Value,
PublishStatus = pageItem.Element("publishStatus").Value,
CorrectionOfId = (int)pageItem.Element("correctionOfId"),
IdCode = pageItem.Element("idCode").Value,
Menu = pageItem.Element("menu").Value,
Title = pageItem.Element("title").Value,
Description = pageItem.Element("description").Value,
AccessGroups = pageItem.Element("accessGroups").Value,
DisplayOrder = (int)pageItem.Element("displayOrder"),
Content = pageItem.Element("content").DescendantNodes() //PSEUDO-CODE
};