Search code examples
asp.netxmldata-bindingdata-storagexmldatasource

Data storage hazards and problems when using XmlDataSource as persistancy layer in an ASP.NET web application


This is a question about how to solve a possible, real, problem occurring when deciding to use xml files to store data in a web application.

The scenario

Consider you want to build a web application in order to run a personal blog. Well, sure, this application needs to store data, and the text is formatted using particular tools (like Markdown for example), where the written content is converted in html.

Sure my xml files will have to store html tags....

The problem

In my xml files, how can I store html data in order not to violate the xsd specified?

For example, if I try to store html tags... the xml validation will sure fail, I suppose...

But the one I mentioned is only one of the possible problems occurring when using xml (for example, databinding will suffer from any possible problem because of what I mentioed before?). Can you tell what is the general approach to this problem (talk about patterns and best practices)?

Thankyou.


Solution

  • To answer the portion of your question about stoing HTML in XML, in your xml file, surround your html in CDATA tags.

    <![CDATA[
    
    html
    
    ]]>