ConvertXmlToObject() private method

private ConvertXmlToObject ( XmlReader xmlReader, XmlRootAttribute xmlAttrib ) : object
xmlReader System.Xml.XmlReader
xmlAttrib System.Xml.Serialization.XmlRootAttribute
return object
コード例 #1
0
ファイル: XmlDataLoader.cs プロジェクト: uQr/referencesource
 private void SetRowValueFromXmlText( DataRow row, DataColumn col, string xmlText ) {
     row[col] = col.ConvertXmlToObject(xmlText);
 }
コード例 #2
0
        private int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
        {
            // read table information
            table = ds.Tables[XmlConvert.DecodeName(row.LocalName), row.NamespaceURI];
            int    iRowDepth = row.Depth;
            string value     = null;

            if (table == null)
            {
                throw ExceptionBuilder.DiffgramMissingTable(XmlConvert.DecodeName(row.LocalName));
            }


            value = row.GetAttribute(Keywords.ROWORDER, Keywords.MSDNS);
            if ((value != null) && (value.Length > 0))
            {
                pos = (Int32)Convert.ChangeType(value, typeof(Int32));
            }

            int record = table.NewRecord();

            foreach (DataColumn col in table.Columns)
            {
                col[record] = DBNull.Value;
            }

            foreach (DataColumn col in table.Columns)
            {
                if ((col.ColumnMapping == MappingType.Element) ||
                    (col.ColumnMapping == MappingType.SimpleContent))
                {
                    continue;
                }

                if (col.ColumnMapping == MappingType.Hidden)
                {
                    value = row.GetAttribute("hidden" + col.EncodedColumnName, Keywords.MSDNS);
                }
                else
                {
                    value = row.GetAttribute(col.EncodedColumnName, col.Namespace);
                }

                if (value == null)
                {
                    continue;
                }

                col[record] = col.ConvertXmlToObject(value);
            }

            row.Read();
            if (row.Depth <= iRowDepth)
            {
                // the node is empty
                return(record);
            }

            if (table.XmlText != null)
            {
                DataColumn col = table.XmlText;
                col[record] = col.ConvertXmlToObject(row.ReadString());
            }
            else
            {
                while (row.Depth > iRowDepth)
                {
                    String     ln     = XmlConvert.DecodeName(row.LocalName);
                    String     ns     = row.NamespaceURI;
                    DataColumn column = table.Columns[ln, ns];

                    if (column == null)
                    {
                        while ((row.NodeType != XmlNodeType.EndElement) && (row.LocalName != ln) && (row.NamespaceURI != ns))
                        {
                            row.Read(); // consume the current node
                        }
                        row.Read();     // now points to the next column
                        continue;       // add a read here!
                    }


                    int iColumnDepth = row.Depth;
                    row.Read();
                    if (row.Depth > iColumnDepth)   //we are inside the column
                    {
                        if (row.NodeType == XmlNodeType.Text)
                        {
                            String text = row.ReadString();
                            column[record] = column.ConvertXmlToObject(text);

                            row.Read(); // now points to the next column
                        }
                    }
                    else
                    {
                        // <element></element> case
                        if (column.DataType == typeof(string))
                        {
                            column[record] = string.Empty;
                        }
                    }
                }
            }
            row.Read(); //now it should point to next row
            return(record);
        }
コード例 #3
0
        private int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
        {
            // read table information
            if (ds != null)
            {
                table = ds.Tables.GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
            }
            else
            {
                table = GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
            }

            if (table == null)
            {
                row.Skip(); // need to skip this element if we dont know about it, before returning -1
                return(-1);
            }

            int    iRowDepth = row.Depth;
            string value     = null;

            value = row.GetAttribute(Keywords.ROWORDER, Keywords.MSDNS);
            if (!string.IsNullOrEmpty(value))
            {
                pos = (int)Convert.ChangeType(value, typeof(int), null);
            }

            int record = table.NewRecord();

            foreach (DataColumn col in table.Columns)
            {
                col[record] = DBNull.Value;
            }

            foreach (DataColumn col in table.Columns)
            {
                if ((col.ColumnMapping == MappingType.Element) ||
                    (col.ColumnMapping == MappingType.SimpleContent))
                {
                    continue;
                }

                if (col.ColumnMapping == MappingType.Hidden)
                {
                    value = row.GetAttribute("hidden" + col.EncodedColumnName, Keywords.MSDNS);
                }
                else
                {
                    value = row.GetAttribute(col.EncodedColumnName, col.Namespace);
                }

                if (value == null)
                {
                    continue;
                }

                col[record] = col.ConvertXmlToObject(value);
            }

            row.Read();
            SkipWhitespaces(row);

            int currentDepth = row.Depth;

            if (currentDepth <= iRowDepth)
            {
                // the node is empty
                if (currentDepth == iRowDepth && row.NodeType == XmlNodeType.EndElement)
                {
                    // read past the EndElement of the current row
                    // note: (currentDepth == iRowDepth) check is needed so we do not skip elements on parent rows.
                    row.Read();
                    SkipWhitespaces(row);
                }
                return(record);
            }

            if (table.XmlText != null)
            {
                DataColumn col = table.XmlText;
                col[record] = col.ConvertXmlToObject(row.ReadString());
            }
            else
            {
                while (row.Depth > iRowDepth)
                {
                    string     ln     = XmlConvert.DecodeName(row.LocalName);
                    string     ns     = row.NamespaceURI;
                    DataColumn column = table.Columns[ln, ns];

                    if (column == null)
                    {
                        while ((row.NodeType != XmlNodeType.EndElement) && (row.LocalName != ln) && (row.NamespaceURI != ns))
                        {
                            row.Read(); // consume the current node
                        }
                        row.Read();     // now points to the next column
                        //SkipWhitespaces(row); seems no need, just in case if we see other issue , this will be here as hint
                        continue;       // add a read here!
                    }

                    if (column.IsCustomType)
                    {
                        // if column's type is object or column type does not implement IXmlSerializable
                        bool isPolymorphism = (column.DataType == typeof(object) || (row.GetAttribute(Keywords.MSD_INSTANCETYPE, Keywords.MSDNS) != null) ||
                                               (row.GetAttribute(Keywords.TYPE, Keywords.XSINS) != null));

                        bool skipped = false;
                        if (column.Table.DataSet != null && column.Table.DataSet._udtIsWrapped)
                        {
                            row.Read(); // if UDT is wrapped, skip the wrapper
                            skipped = true;
                        }

                        XmlRootAttribute xmlAttrib = null;

                        if (!isPolymorphism && !column.ImplementsIXMLSerializable)
                        { // THIS CHECK MAY BE IS WRONG think more
                            // if does not implement IXLSerializable, need to go with XmlSerializer: pass XmlRootAttribute
                            if (skipped)
                            {
                                xmlAttrib           = new XmlRootAttribute(row.LocalName);
                                xmlAttrib.Namespace = row.NamespaceURI;
                            }
                            else
                            {
                                xmlAttrib           = new XmlRootAttribute(column.EncodedColumnName);
                                xmlAttrib.Namespace = column.Namespace;
                            }
                        }
                        // for else case xmlAttrib MUST be null
                        column[record] = column.ConvertXmlToObject(row, xmlAttrib); // you need to pass null XmlAttib here


                        if (skipped)
                        {
                            row.Read(); // if Wrapper is skipped, skip its end tag
                        }
                    }
                    else
                    {
                        int iColumnDepth = row.Depth;
                        row.Read();

                        // SkipWhitespaces(row);seems no need, just in case if we see other issue , this will be here as hint
                        if (row.Depth > iColumnDepth)
                        { //we are inside the column
                            if (row.NodeType == XmlNodeType.Text || row.NodeType == XmlNodeType.Whitespace || row.NodeType == XmlNodeType.SignificantWhitespace)
                            {
                                string text = row.ReadString();
                                column[record] = column.ConvertXmlToObject(text);

                                row.Read(); // now points to the next column
                            }
                        }
                        else
                        {
                            // <element></element> case
                            if (column.DataType == typeof(string))
                            {
                                column[record] = string.Empty;
                            }
                        }
                    }
                }
            }
            row.Read(); //now it should point to next row
            SkipWhitespaces(row);
            return(record);
        }
コード例 #4
0
ファイル: XmlDataLoader.cs プロジェクト: uQr/referencesource
        // 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:
                        case XmlNodeType.CDATA:
                        case XmlNodeType.SignificantWhitespace:
                            if (0 == text.Length) {                 // In case we do not have value already

                                text = dataReader.Value;            // Get value.

                                // See if we have other text nodes near. In most cases this loop will not be executed. 
                                StringBuilder builder = null;
                                while ( dataReader.Read() && entryDepth < dataReader.Depth && IsTextLikeNode(dataReader.NodeType)) {
                                    if (builder == null) {
                                        builder = new StringBuilder(text);
                                    }
                                    builder.Append(dataReader.Value);  // Concatenate other sequential text like
                                                                       // nodes we might have. This is rare.
                                                                       // We're using this instead of dataReader.ReadString()
                                                                       // which would do the same thing but slower.
                                }

                                if (builder != null) {
                                    text = builder.ToString();
                                }
                            }
                            else {
                                dataReader.ReadString();            // We've got column value already. Read this one and ignore it.
                            }
                            break;
                        case XmlNodeType.Element:
                            if (ProcessXsdSchema()) {               // Check for schema. Skip or load if found.
                                continue;                           // Schema has been found. Process the next element 
                                                                    // we're already at (done by schema processing).
                            }
                            else {                              
                                // We've got element which is not supposed to he here.
                                // That might be table which was misplaced.
                                // Or it might be a column inside column (also misplaced).
                                object o = nodeToSchemaMap.GetColumnSchema(column.Table, dataReader, FIgnoreNamespace(dataReader));
                                                                    // Get dataset element for this XML element
                                DataColumn c = o as DataColumn;     // Perhaps, it's a column?
            
                                if ( c != null ) {                  // Do we have matched column in this table?

                                    // Let's load column data
                        
                                    if (foundColumns[c.Ordinal] == null) {
                                                                    // If this column was not found before
                                        LoadColumn (c, foundColumns);            
                                                                    // Get column value
                                    }       
                                    else {
                                        dataReader.Read();          // Already loaded, proceed to the next element
                                    }
                                } 
                                else  {
                                    DataTable nestedTable = o as DataTable; 
                                                                    // Perhaps, it's a nested table ?
                                    if ( nestedTable != null ) {        
                                                                    // Do we have matched table in DataSet ?
                                        LoadTable (nestedTable, true /* isNested */);            
                                                                    // Yes. Load nested table (recursive)
                                    }
                                    else {                          // Not a nested column nor nested table.    
                                                                    // Let's try other tables in the DataSet
        
                                        DataTable misplacedTable = nodeToSchemaMap.GetTableForNode(dataReader, FIgnoreNamespace(dataReader));
                                                                    // Try to get table for node
                                        if (misplacedTable != null) {   
                                                                    // Got some table to match?
                                            LoadTable (misplacedTable, false /* isNested */);                       
                                                                    // While table's XML element is nested,
                                                                    // the table itself is not. Load it this way.
                                        } 
                                        else {
                                            dataReader.Read();      // No match? Try next element
                                        }               
                                    }
                                }
                            }
                            break;
                        case XmlNodeType.EntityReference:           // Oops. No support for Entity Reference
                            throw ExceptionBuilder.FoundEntity();
                        default:
                            dataReader.Read();                      // We don't process that, skip to the next element.
                            break;
                        }
            
                    }

                    dataReader.Read();                              // We're done here. To the next element.
                }

                if (0 == text.Length && xsiNilString != null && XmlConvert.ToBoolean(xsiNilString)) {
                    foundColumns[column.Ordinal] = DBNull.Value;     
                                                                    // If no data and NIL attribute is true set value to null
                }
                else {
                    foundColumns[column.Ordinal] = column.ConvertXmlToObject(text);
                }
    
            }

        }
コード例 #5
0
ファイル: XmlDataDocument.cs プロジェクト: ericeil/corefx
        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;
        }
コード例 #6
0
        private int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
        {
            if (ds != null)
            {
                table = ds.Tables.GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
            }
            else
            {
                table = this.GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
            }
            if (table == null)
            {
                row.Skip();
                return(-1);
            }
            int    depth = row.Depth;
            string str   = null;

            if (table == null)
            {
                throw ExceptionBuilder.DiffgramMissingTable(XmlConvert.DecodeName(row.LocalName));
            }
            str = row.GetAttribute("rowOrder", "urn:schemas-microsoft-com:xml-msdata");
            if (!ADP.IsEmpty(str))
            {
                pos = (int)Convert.ChangeType(str, typeof(int), null);
            }
            int num = table.NewRecord();

            foreach (DataColumn column4 in table.Columns)
            {
                column4[num] = DBNull.Value;
            }
            foreach (DataColumn column2 in table.Columns)
            {
                if ((column2.ColumnMapping != MappingType.Element) && (column2.ColumnMapping != MappingType.SimpleContent))
                {
                    if (column2.ColumnMapping == MappingType.Hidden)
                    {
                        str = row.GetAttribute("hidden" + column2.EncodedColumnName, "urn:schemas-microsoft-com:xml-msdata");
                    }
                    else
                    {
                        str = row.GetAttribute(column2.EncodedColumnName, column2.Namespace);
                    }
                    if (str != null)
                    {
                        column2[num] = column2.ConvertXmlToObject(str);
                    }
                }
            }
            row.Read();
            this.SkipWhitespaces(row);
            if (row.Depth > depth)
            {
                if (table.XmlText == null)
                {
                    while (row.Depth > depth)
                    {
                        string     str3         = XmlConvert.DecodeName(row.LocalName);
                        string     namespaceURI = row.NamespaceURI;
                        DataColumn column       = table.Columns[str3, namespaceURI];
                        if (column == null)
                        {
                            while (((row.NodeType != XmlNodeType.EndElement) && (row.LocalName != str3)) && (row.NamespaceURI != namespaceURI))
                            {
                                row.Read();
                            }
                            row.Read();
                        }
                        else if (column.IsCustomType)
                        {
                            bool flag2 = ((column.DataType == typeof(object)) || (row.GetAttribute("InstanceType", "urn:schemas-microsoft-com:xml-msdata") != null)) || (row.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance") != null);
                            bool flag  = false;
                            if ((column.Table.DataSet != null) && column.Table.DataSet.UdtIsWrapped)
                            {
                                row.Read();
                                flag = true;
                            }
                            XmlRootAttribute xmlAttrib = null;
                            if (!flag2 && !column.ImplementsIXMLSerializable)
                            {
                                if (flag)
                                {
                                    xmlAttrib = new XmlRootAttribute(row.LocalName)
                                    {
                                        Namespace = row.NamespaceURI
                                    };
                                }
                                else
                                {
                                    xmlAttrib = new XmlRootAttribute(column.EncodedColumnName)
                                    {
                                        Namespace = column.Namespace
                                    };
                                }
                            }
                            column[num] = column.ConvertXmlToObject(row, xmlAttrib);
                            if (flag)
                            {
                                row.Read();
                            }
                        }
                        else
                        {
                            int num3 = row.Depth;
                            row.Read();
                            if (row.Depth > num3)
                            {
                                if (((row.NodeType == XmlNodeType.Text) || (row.NodeType == XmlNodeType.Whitespace)) || (row.NodeType == XmlNodeType.SignificantWhitespace))
                                {
                                    string s = row.ReadString();
                                    column[num] = column.ConvertXmlToObject(s);
                                    row.Read();
                                }
                            }
                            else if (column.DataType == typeof(string))
                            {
                                column[num] = string.Empty;
                            }
                        }
                    }
                }
                else
                {
                    DataColumn xmlText = table.XmlText;
                    xmlText[num] = xmlText.ConvertXmlToObject(row.ReadString());
                }
                row.Read();
                this.SkipWhitespaces(row);
            }
            return(num);
        }
コード例 #7
0
        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:
                        case XmlNodeType.Whitespace:
                        case XmlNodeType.SignificantWhitespace:
                            if (s.Length != 0)
                            {
                                goto Label_028C;
                            }
                            s = this.dataReader.Value;
                            goto Label_0252;

                        case XmlNodeType.EntityReference:
                            throw ExceptionBuilder.FoundEntity();

                        default:
                            goto Label_035B;
                        }
Label_0240:
                        s = s + this.dataReader.Value;
Label_0252:
                        if ((this.dataReader.Read() && (depth < this.dataReader.Depth)) && this.IsTextLikeNode(this.dataReader.NodeType))
                        {
                            goto Label_0240;
                        }
                        continue;
Label_028C:
                        this.dataReader.ReadString();
                        continue;
Label_02F3:
                        this.dataReader.Read();
                        continue;
Label_0301:
                        table2 = obj3 as DataTable;
                        if (table2 != null)
                        {
                            this.LoadTable(table2, true);
                        }
                        else
                        {
                            DataTable tableForNode = this.nodeToSchemaMap.GetTableForNode(this.dataReader, this.FIgnoreNamespace(this.dataReader));
                            if (tableForNode != null)
                            {
                                this.LoadTable(tableForNode, false);
                            }
                            else
                            {
                                this.dataReader.Read();
                            }
                        }
                        continue;
Label_035B:
                        this.dataReader.Read();
                    }
                    this.dataReader.Read();
                }
                if (((s.Length == 0) && (str3 != null)) && XmlConvert.ToBoolean(str3))
                {
                    foundColumns[column.Ordinal] = DBNull.Value;
                }
                else
                {
                    foundColumns[column.Ordinal] = column.ConvertXmlToObject(s);
                }
            }
        }
コード例 #8
0
 private void SetRowValueFromXmlText(DataRow row, DataColumn col, string xmlText)
 {
     row[col] = col.ConvertXmlToObject(xmlText);
 }
コード例 #9
0
        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:
                            case XmlNodeType.Whitespace:
                            case XmlNodeType.SignificantWhitespace:
                                if (s.Length != 0)
                                {
                                    goto Label_028C;
                                }
                                s = this.dataReader.Value;
                                goto Label_0252;

                            case XmlNodeType.EntityReference:
                                throw ExceptionBuilder.FoundEntity();

                            default:
                                goto Label_035B;
                        }
                    Label_0240:
                        s = s + this.dataReader.Value;
                    Label_0252:
                        if ((this.dataReader.Read() && (depth < this.dataReader.Depth)) && this.IsTextLikeNode(this.dataReader.NodeType))
                        {
                            goto Label_0240;
                        }
                        continue;
                    Label_028C:
                        this.dataReader.ReadString();
                        continue;
                    Label_02F3:
                        this.dataReader.Read();
                        continue;
                    Label_0301:
                        table2 = obj3 as DataTable;
                        if (table2 != null)
                        {
                            this.LoadTable(table2, true);
                        }
                        else
                        {
                            DataTable tableForNode = this.nodeToSchemaMap.GetTableForNode(this.dataReader, this.FIgnoreNamespace(this.dataReader));
                            if (tableForNode != null)
                            {
                                this.LoadTable(tableForNode, false);
                            }
                            else
                            {
                                this.dataReader.Read();
                            }
                        }
                        continue;
                    Label_035B:
                        this.dataReader.Read();
                    }
                    this.dataReader.Read();
                }
                if (((s.Length == 0) && (str3 != null)) && XmlConvert.ToBoolean(str3))
                {
                    foundColumns[column.Ordinal] = DBNull.Value;
                }
                else
                {
                    foundColumns[column.Ordinal] = column.ConvertXmlToObject(s);
                }
            }
        }