Tuesday, March 9, 2010

Loading xml into a xdoc, and then initializing an object

Programmer Question

My object looks like:



public class Template
{
public string Title {get;set;}
public string Body {get;set;}
}


xml that is stored in /files/test.xml in a web application (at the root):



<nodes>
<template name="someKey">
<node name="title">soem title</node>
<node name="body">some body text here</node>
</template>
</nodes>


So I can load the document like:



XDocument doc = XDocument.Load(HttpContext.Current.Server.MapPath("~/files/test.xml"));


Now how would I load the object from the xml? (say for the template with name = somekey



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails