本文整理汇总了C#中System.Data.DataColumn.ConvertXmlToObject方法的典型用法代码示例。如果您正苦于以下问题:C# DataColumn.ConvertXmlToObject方法的具体用法?C# DataColumn.ConvertXmlToObject怎么用?C# DataColumn.ConvertXmlToObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataColumn
的用法示例。
在下文中一共展示了DataColumn.ConvertXmlToObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetRowValueFromXmlText
private void SetRowValueFromXmlText( DataRow row, DataColumn col, string xmlText ) {
row[col] = col.ConvertXmlToObject(xmlText);
}
示例2: SetRowValueFromXmlText
internal static void SetRowValueFromXmlText(DataRow row, DataColumn col, string xmlText)
{
Debug.Assert(xmlText != null);
Debug.Assert(row.Table.DataSet.EnforceConstraints == false);
object oVal;
try
{
oVal = col.ConvertXmlToObject(xmlText);
// This func does not set the field value to null - call SetRowValueToNull in order to do so
Debug.Assert(oVal != null && !(oVal is DBNull));
}
catch (Exception e) when (Data.Common.ADP.IsCatchableExceptionType(e))
{
// Catch data-type errors and set ROM to Unspecified value
SetRowValueToNull(row, col);
return;
}
if (!oVal.Equals(row[col]))
row[col] = oVal;
}
示例3: LoadColumn
// Returns column value
private void LoadColumn (DataColumn column, object[] foundColumns) {
// <DataSet> /--------------------------------- We are here on entrance
// <Table> /
// <Column>Value</Column>
// <AnotherColumn>Value</AnotherColumn>
// </Table> \------------------------------ We are here on exit
// </DataSet>
// <Column> If we have something like this
// <Foo>FooVal</Foo> We would grab first text-like node
// Value In this case it would be "FooVal"
// <Bar>BarVal</Bar> And not "Value" as you might think
// </Column> This is how desktop works
string text = String.Empty; // Column text. Assume empty string
string xsiNilString = null; // Possible NIL attribute string
int entryDepth = dataReader.Depth; // Store depth so we won't read too much
if (dataReader.AttributeCount > 0) // If have attributes
xsiNilString = dataReader.GetAttribute(Keywords.XSI_NIL, Keywords.XSINS);
// Try to get NIL attribute
// We have to do it before we move to the next element
if (column.IsCustomType) { // Custom type column
object columnValue = null; // Column value we're after. Assume no value.
string xsiTypeString = null; // XSI type name from TYPE attribute
string typeName = null; // Type name from MSD_INSTANCETYPE attribute
XmlRootAttribute xmlAttrib = null; // Might need this attribute for XmlSerializer
if (dataReader.AttributeCount > 0) { // If have attributes, get attributes we'll need
xsiTypeString = dataReader.GetAttribute(Keywords.TYPE, Keywords.XSINS);
typeName = dataReader.GetAttribute(Keywords.MSD_INSTANCETYPE, Keywords.MSDNS);
}
// Check if need to use XmlSerializer. We need to do that if type does not implement IXmlSerializable.
// We also need to do that if no polymorphism for this type allowed.
bool useXmlSerializer = !column.ImplementsIXMLSerializable &&
!( (column.DataType == typeof(Object)) || (typeName != null) || (xsiTypeString != null) );
// Check if we have an attribute telling us value is null.
if ((xsiNilString != null) && XmlConvert.ToBoolean(xsiNilString)) {
if (!useXmlSerializer) { // See if need to set typed null.
if (typeName != null && typeName.Length > 0) {
// Got type name
columnValue = SqlUdtStorage.GetStaticNullForUdtType(DataStorage.GetType(typeName));
}
}
if (null == columnValue) { // If no value,
columnValue = DBNull.Value; // change to DBNull;
}
if ( !dataReader.IsEmptyElement ) // In case element is not empty
while (dataReader.Read() && (entryDepth < dataReader.Depth));
// Read current elements
dataReader.Read(); // And start reading next element.
}
else { // No NIL attribute. Get value
bool skipped = false;
if (column.Table.DataSet != null && column.Table.DataSet.UdtIsWrapped) {
dataReader.Read(); // if UDT is wrapped, skip the wrapper
skipped = true;
}
if (useXmlSerializer) { // Create an attribute for XmlSerializer
if (skipped) {
xmlAttrib = new XmlRootAttribute(dataReader.LocalName);
xmlAttrib.Namespace = dataReader.NamespaceURI ;
}
else {
xmlAttrib = new XmlRootAttribute(column.EncodedColumnName);
xmlAttrib.Namespace = column.Namespace;
}
}
columnValue = column.ConvertXmlToObject(dataReader, xmlAttrib);
// Go get the value
if (skipped) {
dataReader.Read(); // if Wrapper is skipped, skip its end tag
}
}
foundColumns[column.Ordinal] = columnValue; // Store value
}
else { // Not a custom type.
if ( dataReader.Read() && entryDepth < dataReader.Depth) {
// Read to the next element and see if we're inside.
while (entryDepth < dataReader.Depth) {
switch (dataReader.NodeType) { // Process nodes based on type
case XmlNodeType.Text: // It looks like a text. And we need it.
case XmlNodeType.Whitespace:
//.........这里部分代码省略.........
示例4: LoadColumn
private void LoadColumn(DataColumn column, object[] foundColumns)
{
string s = string.Empty;
string str3 = null;
int depth = this.dataReader.Depth;
if (this.dataReader.AttributeCount > 0)
{
str3 = this.dataReader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
}
if (column.IsCustomType)
{
object staticNullForUdtType = null;
string attribute = null;
string str2 = null;
XmlRootAttribute xmlAttrib = null;
if (this.dataReader.AttributeCount > 0)
{
attribute = this.dataReader.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance");
str2 = this.dataReader.GetAttribute("InstanceType", "urn:schemas-microsoft-com:xml-msdata");
}
bool flag2 = !column.ImplementsIXMLSerializable && (((column.DataType != typeof(object)) && (str2 == null)) && (attribute == null));
if ((str3 != null) && XmlConvert.ToBoolean(str3))
{
if ((!flag2 && (str2 != null)) && (str2.Length > 0))
{
staticNullForUdtType = SqlUdtStorage.GetStaticNullForUdtType(DataStorage.GetType(str2));
}
if (staticNullForUdtType == null)
{
staticNullForUdtType = DBNull.Value;
}
if (!this.dataReader.IsEmptyElement)
{
while (this.dataReader.Read() && (depth < this.dataReader.Depth))
{
}
}
this.dataReader.Read();
}
else
{
bool flag = false;
if ((column.Table.DataSet != null) && column.Table.DataSet.UdtIsWrapped)
{
this.dataReader.Read();
flag = true;
}
if (flag2)
{
if (flag)
{
xmlAttrib = new XmlRootAttribute(this.dataReader.LocalName) {
Namespace = this.dataReader.NamespaceURI
};
}
else
{
xmlAttrib = new XmlRootAttribute(column.EncodedColumnName) {
Namespace = column.Namespace
};
}
}
staticNullForUdtType = column.ConvertXmlToObject(this.dataReader, xmlAttrib);
if (flag)
{
this.dataReader.Read();
}
}
foundColumns[column.Ordinal] = staticNullForUdtType;
}
else
{
if (this.dataReader.Read() && (depth < this.dataReader.Depth))
{
while (depth < this.dataReader.Depth)
{
DataTable table2;
object obj3;
switch (this.dataReader.NodeType)
{
case XmlNodeType.Element:
{
if (!this.ProcessXsdSchema())
{
obj3 = this.nodeToSchemaMap.GetColumnSchema(column.Table, this.dataReader, this.FIgnoreNamespace(this.dataReader));
DataColumn column2 = obj3 as DataColumn;
if (column2 == null)
{
goto Label_0301;
}
if (foundColumns[column2.Ordinal] != null)
{
goto Label_02F3;
}
this.LoadColumn(column2, foundColumns);
}
continue;
}
case XmlNodeType.Text:
case XmlNodeType.CDATA:
//.........这里部分代码省略.........