Derek Smyth

Hello,

Bare with me as it's been a long day. I've noticed a bit of a glitch in the way the XmlWriter writes a boolen value and what the DataSet.Read() expects boolean values to be when it reads in Xml.

Basically XmlWriter writes boolean values, taken from a data row, as either True or False. It capitalises the first letter. This xml has been written during serialisation when implementing IXmlSerializable. The serialisation loops over the columns of a datarow and uses the XmlWriters.WriteElementString to output the column name as element name and the data for the column in a row as the elements value.

When this Xml is read in to a DataSet using the Read() method then an exception is thrown, "String 'False' is not a valid Boolean value".

The DataSet writes it's boolean values as true or false (lower case) and these can be read in and converted fine. There is an obvious fix but it feels like an annoyance rather than anything else.

Just want to ask though is there something I'm missing, an option on either the writer or the dataset that will either cause the writer to output lower text boolean or that will allow the dataset to read in capitalised boolean values

 

 




Re: XML and the .NET Framework Slight Difference in XmlWriter and DataSet.Read

Derek Smyth

Hi,

Yeah I just done a String.Replace() on the Xml to replace True->true and False->false and the DataSet read it in ok.

There has to be a better way.






Re: XML and the .NET Framework Slight Difference in XmlWriter and DataSet.Read

Martin Honnen

WriteElementString is not aware of types. Consider to use WriteStartElement to write the start tag, then use WriteValue(YourBoolean) to write out the column boolean value, then WriteEndElement to write the end element. That way true/false will be output.




Re: XML and the .NET Framework Slight Difference in XmlWriter and DataSet.Read

Derek Smyth

Thanks for the reply Martin.




Re: XML and the .NET Framework Slight Difference in XmlWriter and DataSet.Read

elipford

That is exactly what I've done with the code posted below. However, I keep getting nested column errors when I try to run the program.

HPD_xmlOut.WriteStartDocument();

HPD_xmlOut.WriteStartElement("SLA");

HPD_xmlOut.WriteStartElement("HPD_Priority_1");

HPD_xmlOut.WriteStartElement("ID");

HPD_xmlOut.WriteValue(finishSplit[0]);

HPD_xmlOut.WriteEndElement();

HPD_xmlOut.WriteStartElement("Category");

HPD_xmlOut.WriteValue(finishSplit[1]);

HPD_xmlOut.WriteStartElement("Goal");

HPD_xmlOut.WriteValue(double.Parse(finishSplit[2]));

HPD_xmlOut.WriteEndElement();

HPD_xmlOut.WriteStartElement("Incident_Number");

HPD_xmlOut.WriteValue(double.Parse(finishSplit[3]));

HPD_xmlOut.WriteEndElement();

HPD_xmlOut.WriteStartElement("Number_Met");

HPD_xmlOut.WriteValue(double.Parse(finishSplit[4]));

HPD_xmlOut.WriteEndElement();

HPD_xmlOut.WriteStartElement("Percentage_Met");

HPD_xmlOut.WriteValue(double.Parse(finishSplit[5]));

HPD_xmlOut.WriteEndElement();

HPD_xmlOut.WriteStartElement("Average_Time");

HPD_xmlOut.WriteValue(double.Parse(finishSplitDevil));

HPD_xmlOut.WriteEndElement();

HPD_xmlOut.WriteEndElement();

HPD_xmlOut.WriteEndElement();

HPD_xmlOut.WriteEndDocument();

HPD_xmlOut.Close();