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]
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]
980d7a6b-bebe-4ce9-b21c-7807b6b3972e|0|.0
Tags:
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]
0d64f85d-6b29-426d-9b02-c56b59837a7e|0|.0
Tags:
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]
9d786f66-1027-44ef-b994-3f296b881e4c|0|.0
Tags:
Xml
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]
e1d477b3-5f89-48c8-add1-fde1155b8cf0|0|.0
Tags:
Framework | Xml
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
58e5cd47-cae9-44f4-9b92-f8f1b63c7633|0|.0
Tags:
Xml