How to use a CDATA section with an XmlSerializer

by Dominic Zukiewicz 2. February 2010 22:29
Recently, I’ve had to interpret some user input and then place this input into an XML file for processing by BizTalk Server 2006. Unfortunately, BizTalk Server 2006 likes you to encode characters using their XML equivalents. Let me explain.. Background This can seem quite easy using the System.Xml.XmlSerializer, with its ability to automatically generate XML and escape invalid characters for us. There are problems though. Here is a template class: public class TestClass {     public string Element1 { get; set; }     public string Element2 { get; set; }     public string Element3 { get;... [More]

Tags:

Xml | .Net Framework

How to override XML elements and attributes at run-time

by Dominic Zukiewicz 24. March 2008 19:08
Firstly, we'll start with a nice simple bit of XML: <Customer> <FirstName>John</FirstName> <LastName>Smith</LastName></Customer> Think of the situation. You've got your business classes, which serialize to XML. Great! You've named your properties to meaningful names so the XML that comes out is correct for your customer, or you've used the XmlRoot, XmlElement & XmlAttribute attributes to override this, everything is going smoothly. All of a sudden - "We need to modify the XML very slighty so that we have to rename the elements for certain cu... [More]

Tags:

Xml

Catering for NULL values when reading XML

by Dominic Zukiewicz 21. February 2008 12:57
Today, I had a quick look at the problems associated with missing tags in XML. If you are expecting a numeric value and the tag is missing, you'll get (in the case of int), a default to 0. This, of course happens as the assignment never takes place, and when displaying the data, is just reading the compiler assigned default of 0. Now, lets take this a step further, and say you want to cater for it when it is missing, i.e. NULL - how do you do that? The wonderful XmlSerializer will assign a XXXSpecified property with a boolean, when the tag is present. You must have declared this prope... [More]

Tags:

Xml

Forcing a project to use method and class commenting (using XML).

by Dominic Zukiewicz 11. July 2007 09:53
The XML comments in C# are very useful in commenting code for use with the Intellisense. The generated XML file can be used to assist other developers with the parameters, explanations of methods and use of classes. Also, with automated tools like NDoc and SandCastle, you are able to generate documentation for your source code. If you do not comment it in the right places, you can get some ugly red messages saying "<COMMENT MISSING>". The best way to ensure that all of your public methods, properties and classes are commented is to make Visual Studio generate the XML documentation fo... [More]

Tags:

Xml

Loading your XmlDocuments correctly.

by Dominic Zukiewicz 27. April 2007 15:28
Considering how much XML is used and the amount of code I've written to read/write XML, I still make a common mistake! If you ever get this error: System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. Make sure you are using the correct method for the XmlDocument class. For example: string xml = @"<xml version=""1.0""?><node><innerNode/></node>"; string filename = @"C:\\temp.xml"; StreamWriter sw = new StreamWriter(filename); sw.Write(xml); sw.Close(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(filename);  /... [More]

Tags:

Framework | Xml

XML classes without DataSets

by Dominic Zukiewicz 11. April 2007 16:17
Its sometimes easier to read XML straight into the properties of a class instead of reading into a dataset and then extracting the information needed. I have written an article on it, see what you think. Its especially helpful when you have complex XML documents! http://blogs.bdnet.co.uk/dominicz/archive/2007/04/19/Reading-XML-directly-into-classes-instead-of-DataSets.aspx

Tags:

Xml

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar