Using XML data within MVC or User Control

Topics: General, MVC
Dec 1, 2010 at 11:31 AM

What is the best option to connect to XML database of website within an MVC or User Control?

For example in case a User Control wants to read or modify the page structure or reading blog posts from the built-in blog package by a MVC application.

By "best option" I mean no extra efforts when converting to SQL from XML. :-)

A sample code or an article on this is highly appreciated.

Dec 1, 2010 at 11:48 AM
Edited Dec 1, 2010 at 11:49 AM

You can read the page structure via the SitemapNavigator class


var siteMapNavigator = new SitemapNavigator(new DataConnection());

var current = siteMapNavigator.CurrentPageNode;

var root = siteMapNavigator.CurrentHomePageNode;
var childs = root.ChildPages;

to actually change, add or delete pages you have to go through the datafade

var page = DataFacade.BuildNew<IPage>();

DataFacade.Delete<IPage>(p => p.Id == ...);

For reading blogposts you use the datafacade as well with the interface-type that specifies each blogpost.



Dec 1, 2010 at 11:50 AM

Thanks for the tip.

I'll try that out.

Dec 1, 2010 at 11:52 AM

Dec 1, 2010 at 12:12 PM

@Aboo Use the C1 data API to read/write data. Composite C1 will "translate" your LINQ into 'LINQ for XML' when you work with XML stored data and it will use 'LINQ for SQL' when your data is in SQL. Your code is the same - if you one day migrate data from XML to SQL you do not need to modify your code.

You can work with all C1 data types and types you define yourself in the Data perspective of the C1 Console - the programmatic name you specify here become a CLR type and when working in VS2010 you even get intellisense etc.

Beside from the link from napernik check these:

... and the Add, Update, Delete methods,