コード例 #1
0
ファイル: XmlToDatasetMap.cs プロジェクト: mikem8361/runtime
        private static bool AddColumnSchema(XmlNameTable nameTable, DataColumn col, XmlNodeIdHashtable columns)
        {
            string _columnLocalName = XmlConvert.EncodeLocalName(col.ColumnName);
            string columnLocalName  =
                nameTable.Get(_columnLocalName) ??                 // Look it up in a name table
                nameTable.Add(_columnLocalName);                   // Not found? Add it

            col._encodedColumnName = columnLocalName;              // And set it back

            string?columnNamespace = nameTable.Get(col.Namespace); // Get column namespace from nametable

            if (columnNamespace == null)
            {                                                   // Not found ?
                columnNamespace = nameTable.Add(col.Namespace); // Add it
            }
            else
            {
                if (col._columnUri != null)                                    // Update namespace
                {
                    col._columnUri = columnNamespace;
                }
            }
            // Create XmlNodeIdentety
            // for this column
            XmlNodeIdentety idColumn = new XmlNodeIdentety(columnLocalName, columnNamespace);

            columns[idColumn] = col;                                            // And add it to hashtable

            if (col.ColumnName.StartsWith("xml", StringComparison.OrdinalIgnoreCase))
            {
                HandleSpecialColumn(col, nameTable, columns);
            }

            return(true);
        }
コード例 #2
0
		/// <summary>
		/// Resolves custom function in XPath expression.
		/// </summary>
		/// <param name="prefix">The prefix of the function as it appears in the XPath expression.</param>
		/// <param name="name">The name of the function.</param>
		/// <param name="argTypes">An array of argument types for the function being resolved. 
		/// This allows you to select between methods with the same name (for example, overloaded 
		/// methods). </param>
		/// <returns>An IXsltContextFunction representing the function.</returns>
		public override IXsltContextFunction ResolveFunction(string prefix, string name,
			XPathResultType[] argTypes)
		{
			switch (LookupNamespace(nt.Get(prefix)))
			{
				case ExsltNamespaces.DatesAndTimes:
					return GetExtensionFunctionImplementation(exsltDatesAndTimes, name, argTypes);
				case ExsltNamespaces.Math:
					return GetExtensionFunctionImplementation(exsltMath, name, argTypes);
				case ExsltNamespaces.RegularExpressions:
					return GetExtensionFunctionImplementation(exsltRegularExpressions, name, argTypes);
				case ExsltNamespaces.Sets:
					return GetExtensionFunctionImplementation(exsltSets, name, argTypes);
				case ExsltNamespaces.Strings:
					return GetExtensionFunctionImplementation(exsltStrings, name, argTypes);
				case ExsltNamespaces.Random:
					return GetExtensionFunctionImplementation(exsltRandom, name, argTypes);
				case ExsltNamespaces.GdnDatesAndTimes:
					return GetExtensionFunctionImplementation(gdnDatesAndTimes, name, argTypes);
				case ExsltNamespaces.GdnMath:
					return GetExtensionFunctionImplementation(gdnMath, name, argTypes);
				case ExsltNamespaces.GdnRegularExpressions:
					return GetExtensionFunctionImplementation(gdnRegularExpressions, name, argTypes);
				case ExsltNamespaces.GdnSets:
					return GetExtensionFunctionImplementation(gdnSets, name, argTypes);
				case ExsltNamespaces.GdnStrings:
					return GetExtensionFunctionImplementation(gdnStrings, name, argTypes);
				case ExsltNamespaces.GdnDynamic:
					return GetExtensionFunctionImplementation(gdnDynamic, name, argTypes);
				default:
					throw new XPathException(string.Format("Unrecognized extension function namespace: prefix='{0}', namespace URI='{1}'",
						prefix, LookupNamespace(nt.Get(prefix))), null);
			}
		}
コード例 #3
0
ファイル: XmlToDatasetMap.cs プロジェクト: mikem8361/runtime
        private static void HandleSpecialColumn(DataColumn col, XmlNameTable nameTable, XmlNodeIdHashtable columns)
        {
            // if column name starts with xml, we encode it manually and add it for look up
            Debug.Assert(col.ColumnName.StartsWith("xml", StringComparison.OrdinalIgnoreCase), "column name should start with xml");
            string tempColumnName;

            if ('x' == col.ColumnName[0])
            {
                tempColumnName = "_x0078_"; // lower case xml... -> _x0078_ml...
            }
            else
            {
                tempColumnName = "_x0058_"; // upper case Xml... -> _x0058_ml...
            }

            tempColumnName = string.Concat(tempColumnName, col.ColumnName.AsSpan(1));

            if (nameTable.Get(tempColumnName) == null)
            {
                nameTable.Add(tempColumnName);
            }
            string?         columnNamespace = nameTable.Get(col.Namespace);
            XmlNodeIdentety idColumn        = new XmlNodeIdentety(tempColumnName, columnNamespace);

            columns[idColumn] = col;
        }
コード例 #4
0
        public int Variation_10()
        {
            string filename = null;

            TestFiles.CreateTestFile(ref filename, EREADER_TYPE.BIG_ELEMENT_SIZE);
            XmlReader rDataReader = XmlReader.Create(FilePathUtil.getStream(filename));

            while (rDataReader.Read() == true)
            {
                ;
            }
            XmlNameTable nt       = rDataReader.NameTable;
            object       objTest1 = nt.Get(BigStr + "Z");
            object       objTest2 = nt.Get(BigStr + "X");
            object       objTest3 = nt.Get(BigStr + "Y");

            if (objTest1 != null)
            {
                throw new CTestException(CTestBase.TEST_FAIL, "objTest1 is not null");
            }
            if (objTest2 == null)
            {
                throw new CTestException(CTestBase.TEST_FAIL, "objTest2 is null");
            }
            if (objTest3 == null)
            {
                throw new CTestException(CTestBase.TEST_FAIL, "objTest3 is  null");
            }

            if ((objTest1 == objTest2) || (objTest1 == objTest3) || (objTest2 == objTest3))
            {
                throw new CTestException(CTestBase.TEST_FAIL, "objTest1 is equal to objTest2, or objTest3");
            }
            return(TEST_PASS);
        }
コード例 #5
0
        public int Variation_8()
        {
            ////////////////////////////
            // Add strings again and verify

            string filename = null;

            TestFiles.CreateTestFile(ref filename, EREADER_TYPE.BIG_ELEMENT_SIZE);
            XmlReader rDataReader = XmlReader.Create(FilePathUtil.getStream(filename));

            while (rDataReader.Read() == true)
            {
                ;
            }
            XmlNameTable nt = rDataReader.NameTable;

            string strTest = BigStr + "X";

            char[] chTest     = strTest.ToCharArray();
            Object objActual1 = nt.Add(chTest, 0, chTest.Length);
            Object objActual2 = nt.Add(chTest, 0, chTest.Length);

            CError.Compare(objActual1, objActual2, "Comparing objActual1 and objActual2");
            CError.Compare(objActual1, nt.Get(chTest, 0, chTest.Length), "Comparing objActual1 and GetCharArray");
            CError.Compare(objActual1, nt.Get(strTest), "Comparing objActual1 and GetString");
            CError.Compare(objActual1, nt.Add(strTest), "Comparing objActual1 and AddString");

            TestFiles.RemoveDataReader(EREADER_TYPE.BIG_ELEMENT_SIZE);

            return(TEST_PASS);
        }
コード例 #6
0
        private bool AddColumnSchema(XmlNameTable nameTable, DataColumn col, XmlNodeIdHashtable columns)
        {
            string array     = XmlConvert.EncodeLocalName(col.ColumnName);
            string localName = nameTable.Get(array);

            if (localName == null)
            {
                localName = nameTable.Add(array);
            }
            col.encodedColumnName = localName;
            string namespaceURI = nameTable.Get(col.Namespace);

            if (namespaceURI == null)
            {
                namespaceURI = nameTable.Add(col.Namespace);
            }
            else if (col._columnUri != null)
            {
                col._columnUri = namespaceURI;
            }
            XmlNodeIdentety identety = new XmlNodeIdentety(localName, namespaceURI);

            columns[identety] = col;
            if (col.ColumnName.StartsWith("xml", StringComparison.OrdinalIgnoreCase))
            {
                this.HandleSpecialColumn(col, nameTable, columns);
            }
            return(true);
        }
コード例 #7
0
        private bool AddColumnSchema(XmlNameTable nameTable, DataColumn col, XmlNodeIdHashtable columns)
        {
            string _columnLocalName = XmlConvert.EncodeName(col.ColumnName);
            string columnLocalName  = nameTable.Get(_columnLocalName);

            if (columnLocalName == null)
            {
                columnLocalName = nameTable.Add(_columnLocalName);
            }
            col.encodedColumnName = columnLocalName;

            string columnNamespace = nameTable.Get(col.Namespace);

            if (columnNamespace == null)
            {
                columnNamespace = nameTable.Add(col.Namespace);
            }
            else
            {
                if (col._columnUri != null)
                {
                    col._columnUri = columnNamespace;
                }
            }

            XmlNodeIdentety idColumn = new XmlNodeIdentety(columnLocalName, columnNamespace);

            columns[idColumn] = col;
            return(true);
        }
コード例 #8
0
        private TableSchemaInfo AddTableSchema(XmlNameTable nameTable, DataTable table)
        {
            string encodedTableName = table.EncodedTableName;
            string localName        = nameTable.Get(encodedTableName);

            if (localName == null)
            {
                localName = nameTable.Add(encodedTableName);
            }
            table.encodedTableName = localName;
            string namespaceURI = nameTable.Get(table.Namespace);

            if (namespaceURI == null)
            {
                namespaceURI = nameTable.Add(table.Namespace);
            }
            else if (table.tableNamespace != null)
            {
                table.tableNamespace = namespaceURI;
            }
            TableSchemaInfo info = new TableSchemaInfo(table);

            this.tableSchemaMap[new XmlNodeIdentety(localName, namespaceURI)] = info;
            return(info);
        }
コード例 #9
0
ファイル: XmlToDatasetMap.cs プロジェクト: mikem8361/runtime
        private void BuildIdentityMap(XmlNameTable nameTable, DataSet dataSet)
        {
            _tableSchemaMap = new XmlNodeIdHashtable(dataSet.Tables.Count);
            // This hash table contains
            // tables schemas as TableSchemaInfo objects
            // These objects holds reference to the table.
            // Hash tables with columns schema maps
            // and child tables schema maps

            string dsNamespace =
                nameTable.Get(dataSet.Namespace) ?? // Attempt to look up DataSet namespace in the name table
                nameTable.Add(dataSet.Namespace);   //  Found? Nope. Add it

            dataSet._namespaceURI = dsNamespace;    // Set a DataSet namespace URI

            foreach (DataTable t in dataSet.Tables)
            {                    // For each table
                TableSchemaInfo tableSchemaInfo = AddTableSchema(nameTable, t);
                // Add table schema info to hash table

                if (tableSchemaInfo != null)
                {
                    foreach (DataColumn c in t.Columns)
                    {              // Add column schema map
                        // don't include auto-generated PK, FK and any hidden columns to be part of mapping
                        if (IsMappedColumn(c))
                        {                        // If mapped column
                            AddColumnSchema(nameTable, c, tableSchemaInfo.ColumnsSchemaMap);
                        }                        // Add it to the map
                    }

                    // Add child nested tables to the schema

                    foreach (DataRelation r in t.ChildRelations)
                    {     // Do we have a child tables ?
                        if (r.Nested)
                        { // Is it nested?
                            // don't include non nested tables

                            // Handle namespaces and names as usuall

                            string _tableLocalName = XmlConvert.EncodeLocalName(r.ChildTable.TableName);
                            string?tableLocalName  =
                                nameTable.Get(_tableLocalName) ??
                                nameTable.Add(_tableLocalName);

                            string?tableNamespace =
                                nameTable.Get(r.ChildTable.Namespace) ??
                                nameTable.Add(r.ChildTable.Namespace);

                            XmlNodeIdentety idTable = new XmlNodeIdentety(tableLocalName, tableNamespace);
                            tableSchemaInfo.ColumnsSchemaMap[idTable] = r.ChildTable;
                        }
                    }
                }
            }
        }
コード例 #10
0
        // This one is used while reading data with preloaded schema

        private void BuildIdentityMap(XmlNameTable nameTable, DataTable dataTable)
        {
            ArrayList tableList = GetSelfAndDescendants(dataTable);     // Get list of tables we're loading

            // This includes our table and
            // related tables tree

            this.tableSchemaMap = new XmlNodeIdHashtable(tableList.Count);
            // Create hash table to hold all
            // tables to load.

            foreach (DataTable t in tableList)                          // For each table

            {
                TableSchemaInfo tableSchemaInfo = AddTableSchema(nameTable, t);
                // Create schema info
                if (tableSchemaInfo != null)
                {
                    foreach (DataColumn c in t.Columns)                 // Add column information
                    // don't include auto-generated PK, FK and any hidden columns to be part of mapping
                    {
                        if (IsMappedColumn(c))
                        {
                            AddColumnSchema(nameTable, c, tableSchemaInfo.ColumnsSchemaMap);
                        }
                    }

                    foreach (DataRelation r in t.ChildRelations)        // Add nested tables information
                    {
                        if (r.Nested)                                   // Is it nested?
                        // don't include non nested tables

                        // Handle namespaces and names as usuall

                        {
                            string _tableLocalName = XmlConvert.EncodeLocalName(r.ChildTable.TableName);
                            string tableLocalName  = nameTable.Get(_tableLocalName);

                            if (tableLocalName == null)
                            {
                                tableLocalName = nameTable.Add(_tableLocalName);
                            }

                            string tableNamespace = nameTable.Get(r.ChildTable.Namespace);

                            if (tableNamespace == null)
                            {
                                tableNamespace = nameTable.Add(r.ChildTable.Namespace);
                            }

                            XmlNodeIdentety idTable = new XmlNodeIdentety(tableLocalName, tableNamespace);
                            tableSchemaInfo.ColumnsSchemaMap[idTable] = r.ChildTable;
                        }
                    }
                }
            }
        }
コード例 #11
0
        public MFTestResults SPOTXml_NameTableTest5()
        {
            /// <summary>
            /// Tests the NameTable class under SPOT.Xml
            /// </summary>
            ///
            bool testResult = true;

            try
            {
                XmlReader testReader = XmlReader.Create(new TestStream());

                XmlNameTable testNT   = new XmlNameTable();
                object       root     = testNT.Add("root");
                object       element1 = testNT.Add("TestElement1");
                testReader.Read();
                object localName = testReader.LocalName;
                if (!(localName == root))
                {
                    Log.Exception("1st reading, expected local name '" + root + "' but got '" + localName + "'");
                    testResult = false;
                }
                testReader.Read();
                localName = testReader.LocalName;
                if (!(localName == element1))
                {
                    Log.Exception("2nd reading, expected local name '" + element1 + "' but got '" + localName + "'");
                    testResult = false;
                }

                testNT.Add("test1");

                if (testNT.Get("root").GetType() != Type.GetType("System.String"))
                {
                    testResult = false;
                    Log.Exception("Get(string) got wrong type");
                }

                if (testNT.Get("root") != "root")
                {
                    testResult = false;
                    Log.Exception("Get(string) got wrong data");
                }
            }
            catch (Exception e)
            {
                testResult = false;
                Log.Exception("Incorrect exception caught: ", e);
            }
            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
コード例 #12
0
        private TableSchemaInfo AddTableSchema(DataTable table, XmlNameTable nameTable)
        {
            string localName    = nameTable.Get(table.EncodedTableName);
            string namespaceURI = nameTable.Get(table.Namespace);

            if (localName == null)
            {
                return(null);
            }
            TableSchemaInfo info = new TableSchemaInfo(table);

            this.tableSchemaMap[new XmlNodeIdentety(localName, namespaceURI)] = info;
            return(info);
        }
コード例 #13
0
        private bool AddColumnSchema(DataColumn col, XmlNameTable nameTable, XmlNodeIdHashtable columns)
        {
            string columnLocalName = nameTable.Get(col.EncodedColumnName);
            string columnNamespace = nameTable.Get(col.Namespace);

            if (columnLocalName == null)
            {
                return(false);
            }
            XmlNodeIdentety idColumn = new XmlNodeIdentety(columnLocalName, columnNamespace);

            columns[idColumn] = col;
            return(true);
        }
コード例 #14
0
ファイル: outkeywords.cs プロジェクト: SSCLI/sscli_20021101
        private void CheckKeyword(string keyword)
        {
#if DEBUG
            Debug.Assert(keyword != null);
            Debug.Assert((object)keyword == (object)_NameTable.Get(keyword));
#endif
        }
コード例 #15
0
ファイル: XmlToDatasetMap.cs プロジェクト: wilfriedb/runtime
        private TableSchemaInfo AddTableSchema(XmlNameTable nameTable, DataTable table)
        {
            // Enzol:This is the opposite of the previous function:
            //       we populate the nametable so that the hash comparison can happen as
            //       object comparison instead of strings.
            // Sdub: GetIdentity is called from two places: BuildIdentityMap() and LoadRows()
            //       First case deals with decoded names; Second one with encoded names.
            //       We decided encoded names in first case (instead of decoding them in second)
            //       because it save us time in LoadRows(). We have, as usual, more data them schemas

            string _tableLocalName = table.EncodedTableName;            // Table name

            string?tableLocalName = nameTable.Get(_tableLocalName);     // Look it up in nametable

            if (tableLocalName == null)
            {                                                    // If not found
                tableLocalName = nameTable.Add(_tableLocalName); // Add it
            }

            table._encodedTableName = tableLocalName;                    // And set it back

            string?tableNamespace = nameTable.Get(table.Namespace);      // Look ip table namespace

            if (tableNamespace == null)
            {                                                    // If not found
                tableNamespace = nameTable.Add(table.Namespace); // Add it
            }
            else
            {
                if (table._tableNamespace != null)                       // Update table namespace
                {
                    table._tableNamespace = tableNamespace;
                }
            }


            TableSchemaInfo tableSchemaInfo = new TableSchemaInfo(table);

            // Create new table schema info
            _tableSchemaMap[new XmlNodeIdentety(tableLocalName, tableNamespace)] = tableSchemaInfo;
            // And add it to the hashtable
            return(tableSchemaInfo);                                     // Return it as we have to populate
                                                                         // Column schema map and Child table
                                                                         // schema map in it
        }
コード例 #16
0
        private bool AddColumnSchema(DataColumn col, XmlNameTable nameTable, XmlNodeIdHashtable columns)
        {
            string localName    = nameTable.Get(col.EncodedColumnName);
            string namespaceURI = nameTable.Get(col.Namespace);

            if (localName == null)
            {
                return(false);
            }
            XmlNodeIdentety identety = new XmlNodeIdentety(localName, namespaceURI);

            columns[identety] = col;
            if (col.ColumnName.StartsWith("xml", StringComparison.OrdinalIgnoreCase))
            {
                this.HandleSpecialColumn(col, nameTable, columns);
            }
            return(true);
        }
コード例 #17
0
        private void BuildIdentityMap(XmlNameTable nameTable, DataSet dataSet)
        {
            this.tableSchemaMap = new XmlNodeIdHashtable(dataSet.Tables.Count);
            string str3 = nameTable.Get(dataSet.Namespace);

            if (str3 == null)
            {
                str3 = nameTable.Add(dataSet.Namespace);
            }
            dataSet.namespaceURI = str3;
            foreach (DataTable table in dataSet.Tables)
            {
                TableSchemaInfo info = this.AddTableSchema(nameTable, table);
                if (info != null)
                {
                    foreach (DataColumn column in table.Columns)
                    {
                        if (IsMappedColumn(column))
                        {
                            this.AddColumnSchema(nameTable, column, info.ColumnsSchemaMap);
                        }
                    }
                    foreach (DataRelation relation in table.ChildRelations)
                    {
                        if (relation.Nested)
                        {
                            string array     = XmlConvert.EncodeLocalName(relation.ChildTable.TableName);
                            string localName = nameTable.Get(array);
                            if (localName == null)
                            {
                                localName = nameTable.Add(array);
                            }
                            string namespaceURI = nameTable.Get(relation.ChildTable.Namespace);
                            if (namespaceURI == null)
                            {
                                namespaceURI = nameTable.Add(relation.ChildTable.Namespace);
                            }
                            XmlNodeIdentety identety = new XmlNodeIdentety(localName, namespaceURI);
                            info.ColumnsSchemaMap[identety] = relation.ChildTable;
                        }
                    }
                }
            }
        }
コード例 #18
0
        internal string GeneratePrefix(string format)
        {
            string prefix;

            do
            {
                prefix = string.Format(CultureInfo.InvariantCulture, format, _prefixIndex++);
            } while (_nameTable.Get(prefix) != null);

            return(_nameTable.Add(prefix));
        }
コード例 #19
0
        /// <summary>
        /// Get the named node pointer from the name table or add it to table if new
        /// </summary>
        /// <param name="table"></param>
        /// <param name="array"></param>
        /// <returns></returns>
        public static string GetOrAdd(this XmlNameTable table, string array)
        {
            var s = table.Get(array);

            if (s == null)
            {
                return(table.Add(array));
            }

            return(s);
        }
コード例 #20
0
        public MFTestResults AddGetTest2()
        {
            try
            {
                XmlNameTable nt = new XmlNameTable();

                String atomized = nt.Add("http://www.microsoft.com/netmf");

                Assert.AreEqual(null, nt.Get("http://www.microsoft.com/netmf/v4"));
                Assert.AreEqual(null, nt.Get("http://www.microsoft.com/"));
                Assert.AreEqual(null, nt.Get("http://www.microsoft.com/netMF"));
            }
            catch (Exception e)
            {
                Log.Exception("Unexpected exception", e);
                return(MFTestResults.Fail);
            }

            return(MFTestResults.Pass);
        }
コード例 #21
0
        private bool AddChildTableSchema(XmlNameTable nameTable, DataRelation rel, XmlNodeIdHashtable childtables)
        {
            string _tableLocalName = XmlConvert.EncodeName(rel.ChildTable.TableName);
            string tableLocalName  = nameTable.Get(_tableLocalName);

            if (tableLocalName == null)
            {
                tableLocalName = nameTable.Add(_tableLocalName);
            }

            string tableNamespace = nameTable.Get(rel.ChildTable.Namespace);

            if (tableNamespace == null)
            {
                tableNamespace = nameTable.Add(rel.ChildTable.Namespace);
            }

            XmlNodeIdentety idTable = new XmlNodeIdentety(tableLocalName, tableNamespace);

            childtables[idTable] = rel;
            return(true);
        }
コード例 #22
0
        private void HandleSpecialColumn(DataColumn col, XmlNameTable nameTable, XmlNodeIdHashtable columns)
        {
            string str;

            if ('x' == col.ColumnName[0])
            {
                str = "_x0078_";
            }
            else
            {
                str = "_x0058_";
            }
            str = str + col.ColumnName.Substring(1);
            if (nameTable.Get(str) == null)
            {
                nameTable.Add(str);
            }
            string          namespaceURI = nameTable.Get(col.Namespace);
            XmlNodeIdentety identety     = new XmlNodeIdentety(str, namespaceURI);

            columns[identety] = col;
        }
コード例 #23
0
        public void NewNamespaceManager()
        {
            // make sure that you can call PopScope when there aren't any to pop.
            Assert.IsTrue(!namespaceManager.PopScope());

            // the following strings should have been added to the name table by the
            // namespace manager.
            string xmlnsPrefix    = nameTable.Get("xmlns");
            string xmlPrefix      = nameTable.Get("xml");
            string stringEmpty    = nameTable.Get(String.Empty);
            string xmlnsNamespace = "http://www.w3.org/2000/xmlns/";
            string xmlNamespace   = "http://www.w3.org/XML/1998/namespace";

            // none of them should be null.
            Assert.IsNotNull(xmlnsPrefix);
            Assert.IsNotNull(xmlPrefix);
            Assert.IsNotNull(stringEmpty);
            Assert.IsNotNull(xmlnsNamespace);
            Assert.IsNotNull(xmlNamespace);

            // Microsoft's XmlNamespaceManager reports that these three
            // namespaces aren't declared for some reason.
            Assert.IsTrue(!namespaceManager.HasNamespace("xmlns"));
            Assert.IsTrue(!namespaceManager.HasNamespace("xml"));
            Assert.IsTrue(!namespaceManager.HasNamespace(String.Empty));

            // these three namespaces are declared by default.
            Assert.AreEqual("http://www.w3.org/2000/xmlns/", namespaceManager.LookupNamespace("xmlns"));
            Assert.AreEqual("http://www.w3.org/XML/1998/namespace", namespaceManager.LookupNamespace("xml"));
            Assert.AreEqual(String.Empty, namespaceManager.LookupNamespace(String.Empty));

            // the namespaces should be the same references found in the name table.
            Assert.AreSame(xmlnsNamespace, namespaceManager.LookupNamespace("xmlns"));
            Assert.AreSame(xmlNamespace, namespaceManager.LookupNamespace("xml"));
            Assert.AreSame(stringEmpty, namespaceManager.LookupNamespace(String.Empty));

            // looking up undeclared namespaces should return null.
            Assert.IsNull(namespaceManager.LookupNamespace("foo"));
        }
コード例 #24
0
        /// <summary>
        /// Gets the atomic string.
        /// </summary>
        /// <param name="v">The v.</param>
        /// <returns></returns>
        private string GetAtomicString(string v)
        {
            string s;

            s = m_nt.Get(v);

            if (s == null)
            {
                s = m_nt.Add(v);
            }

            return(s);
        }
コード例 #25
0
        private TableSchemaInfo AddTableSchema(XmlNameTable nameTable, DataTable table)
        {
            // Enzol:This is the opposite of the previous function:
            //       we populate the nametable so that the hash comparison can happen as
            //       object comparison instead of strings.
            // Sdub: GetIdentity is called from two places: BuildIdentityMap() and LoadRows()
            //       First case deals with decoded names; Second one with encoded names.
            //       We decided encoded names in first case (instead of decoding them in second)
            //       because it save us time in LoadRows(). We have, as usual, more data them schemas

            string _tableLocalName = table.EncodedTableName;
            string tableLocalName  = nameTable.Get(_tableLocalName);

            if (tableLocalName == null)
            {
                tableLocalName = nameTable.Add(_tableLocalName);
            }
            table.encodedTableName = tableLocalName;

            string tableNamespace = nameTable.Get(table.Namespace);

            if (tableNamespace == null)
            {
                tableNamespace = nameTable.Add(table.Namespace);
            }
            else
            {
                if (table.tableNamespace != null)
                {
                    table.tableNamespace = tableNamespace;
                }
            }

            TableSchemaInfo tableSchemaInfo = new TableSchemaInfo(table);

            tableSchemaMap[new XmlNodeIdentety(tableLocalName, tableNamespace)] = tableSchemaInfo;
            return(tableSchemaInfo);
        }
コード例 #26
0
ファイル: XmlToDatasetMap.cs プロジェクト: mikem8361/runtime
        // Used to infere schema

        private TableSchemaInfo?AddTableSchema(DataTable table, XmlNameTable nameTable)
        {
            // SDUB: Because in our case reader already read the document all names that we can meet in the
            //       document already has an entry in NameTable.
            //       If in future we will build identity map before reading XML we can replace Get() to Add()
            // Sdub: GetIdentity is called from two places: BuildIdentityMap() and LoadRows()
            //       First case deals with decoded names; Second one with encoded names.
            //       We decided encoded names in first case (instead of decoding them in second)
            //       because it save us time in LoadRows(). We have, as usual, more data them schemas
            string?tableLocalName = nameTable.Get(table.EncodedTableName);
            string?tableNamespace = nameTable.Get(table.Namespace);

            if (tableLocalName == null)
            {
                // because name of this table isn't present in XML we don't need mapping for it.
                // Less mapping faster we work.
                return(null);
            }
            TableSchemaInfo tableSchemaInfo = new TableSchemaInfo(table);

            _tableSchemaMap[new XmlNodeIdentety(tableLocalName, tableNamespace)] = tableSchemaInfo;
            return(tableSchemaInfo);
        }
コード例 #27
0
        /// <summary>
        /// Extends Get so that buffer offset of 0 and call to Array.Length are not needed.
        /// <example>
        /// xmlnametable.Get(array);
        /// </example>
        /// </summary>
        public static String Get(this XmlNameTable xmlnametable, Char[] array)
        {
            if (xmlnametable == null)
            {
                throw new ArgumentNullException("xmlnametable");
            }

            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            return(xmlnametable.Get(array, 0, array.Length));
        }
コード例 #28
0
 public string LookupNamespace(string prefix)
 {
     Debug.Assert(prefix != null);
     prefix = _nameTable.Get(prefix);
     for (var i = _lastRecord - 2; 0 <= i; i--)
     {
         var record = _records[i];
         if (record.Local == null && RefEquals(record.Prefix, prefix))
         {
             return(record.NsUri);
         }
     }
     return(null);
 }
コード例 #29
0
        public MFTestResults AddGetTest1()
        {
            try
            {
                XmlNameTable nt              = new XmlNameTable();
                String[]     strings         = new String[100];
                String[]     atomizedStrings = new String[100];
                String       str;
                String       atomized;


                for (int i = 0; i < 100; i++)
                {
                    str        = ToNumString(i);
                    strings[i] = str;

                    atomizedStrings[i] = nt.Add(str);

                    Assert.AreEqual(str, atomizedStrings[i]);
                }

                for (int i = 99; i >= 0; i--)
                {
                    str      = ToNumString(i);
                    atomized = nt.Get(str);
                    if (Object.ReferenceEquals(str, atomized))
                    {
                        Log.Comment("The new string and atomized string are of the same reference");
                    }

                    Assert.AreEqual(str, atomized);
                    Assert.IsTrue(Object.ReferenceEquals(atomizedStrings[i], atomized), "String not atomized");
                }
            }
            catch (Exception e)
            {
                Log.Exception("Unexpected exception", e);
                return(MFTestResults.Fail);
            }

            return(MFTestResults.Pass);
        }
コード例 #30
0
        private void BuildIdentityMap(XmlNameTable nameTable, DataSet dataSet)
        {
            this.tableSchemaMap = new XmlNodeIdHashtable(dataSet.Tables.Count);

            string dsNamespace = nameTable.Get(dataSet.Namespace);

            if (dsNamespace == null)
            {
                dsNamespace = nameTable.Add(dataSet.Namespace);
            }
            dataSet.namespaceURI = dsNamespace;

            foreach (DataTable t in dataSet.Tables)
            {
                TableSchemaInfo tableSchemaInfo = AddTableSchema(nameTable, t);
                if (tableSchemaInfo != null)
                {
                    foreach (DataColumn c in t.Columns)
                    {
                        // don't include auto-generated PK, FK and any hidden columns to be part of mapping
                        if (IsMappedColumn(c))
                        {
                            AddColumnSchema(nameTable, c, tableSchemaInfo.ColumnsSchemaMap);
                        }
                    }

                    foreach (DataRelation r in t.ChildRelations)
                    {
                        if (r.Nested)
                        {
                            // don't include non nested tables
                            AddChildTableSchema(nameTable, r, tableSchemaInfo.ChildTablesSchemaMap);
                        }
                    }
                }
            }
        }
コード例 #31
0
ファイル: XPathDocument.cs プロジェクト: Corillian/corefx
        /// <summary>
        /// Create a writer that can be used to create nodes in this document.  The root node will be assigned "baseUri", and flags
        /// can be passed to indicate that names should be atomized by the builder and/or a fragment should be created.
        /// </summary>
        internal void LoadFromReader(XmlReader reader, XmlSpace space)
        {
            XPathDocumentBuilder builder;
            IXmlLineInfo lineInfo;
            string xmlnsUri;
            bool topLevelReader;
            int initialDepth;

            if (reader == null)
                throw new ArgumentNullException(nameof(reader));

            // Determine line number provider
            lineInfo = reader as IXmlLineInfo;
            if (lineInfo == null || !lineInfo.HasLineInfo())
                lineInfo = null;
            _hasLineInfo = (lineInfo != null);

            _nameTable = reader.NameTable;
            builder = new XPathDocumentBuilder(this, lineInfo, reader.BaseURI, LoadFlags.None);

            try
            {
                // Determine whether reader is in initial state
                topLevelReader = (reader.ReadState == ReadState.Initial);
                initialDepth = reader.Depth;

                // Get atomized xmlns uri
                Debug.Assert((object)_nameTable.Get(string.Empty) == (object)string.Empty, "NameTable must contain atomized string.Empty");
                xmlnsUri = _nameTable.Get(XmlReservedNs.NsXmlNs);

                // Read past Initial state; if there are no more events then load is complete
                if (topLevelReader && !reader.Read())
                    return;

                // Read all events
                do
                {
                    // If reader began in intermediate state, return when all siblings have been read
                    if (!topLevelReader && reader.Depth < initialDepth)
                        return;

                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            {
                                bool isEmptyElement = reader.IsEmptyElement;

                                builder.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.BaseURI);

                                // Add attribute and namespace nodes to element
                                while (reader.MoveToNextAttribute())
                                {
                                    string namespaceUri = reader.NamespaceURI;

                                    if ((object)namespaceUri == (object)xmlnsUri)
                                    {
                                        if (reader.Prefix.Length == 0)
                                        {
                                            // Default namespace declaration "xmlns"
                                            Debug.Assert(reader.LocalName == "xmlns");
                                            builder.WriteNamespaceDeclaration(string.Empty, reader.Value);
                                        }
                                        else
                                        {
                                            Debug.Assert(reader.Prefix == "xmlns");
                                            builder.WriteNamespaceDeclaration(reader.LocalName, reader.Value);
                                        }
                                    }
                                    else
                                    {
                                        builder.WriteStartAttribute(reader.Prefix, reader.LocalName, namespaceUri);
                                        builder.WriteString(reader.Value, TextBlockType.Text);
                                        builder.WriteEndAttribute();
                                    }
                                }

                                if (isEmptyElement)
                                    builder.WriteEndElement(true);
                                break;
                            }

                        case XmlNodeType.EndElement:
                            builder.WriteEndElement(false);
                            break;

                        case XmlNodeType.Text:
                        case XmlNodeType.CDATA:
                            builder.WriteString(reader.Value, TextBlockType.Text);
                            break;

                        case XmlNodeType.SignificantWhitespace:
                            if (reader.XmlSpace == XmlSpace.Preserve)
                                builder.WriteString(reader.Value, TextBlockType.SignificantWhitespace);
                            else
                                // Significant whitespace without xml:space="preserve" is not significant in XPath/XQuery data model
                                goto case XmlNodeType.Whitespace;
                            break;

                        case XmlNodeType.Whitespace:
                            // We intentionally ignore the reader.XmlSpace property here and blindly trust
                            //   the reported node type. If the reported information is not in sync
                            //   (in this case if the reader.XmlSpace == Preserve) then we make the choice
                            //   to trust the reported node type. Since we have no control over the input reader
                            //   we can't even assert here.

                            // Always filter top-level whitespace
                            if (space == XmlSpace.Preserve && (!topLevelReader || reader.Depth != 0))
                                builder.WriteString(reader.Value, TextBlockType.Whitespace);
                            break;

                        case XmlNodeType.Comment:
                            builder.WriteComment(reader.Value);
                            break;

                        case XmlNodeType.ProcessingInstruction:
                            builder.WriteProcessingInstruction(reader.LocalName, reader.Value, reader.BaseURI);
                            break;

                        case XmlNodeType.EntityReference:
                            reader.ResolveEntity();
                            break;

                        case XmlNodeType.DocumentType:
                            // Create ID tables
                            IDtdInfo info = reader.DtdInfo;
                            if (info != null)
                                builder.CreateIdTables(info);
                            break;

                        case XmlNodeType.EndEntity:
                        case XmlNodeType.None:
                        case XmlNodeType.XmlDeclaration:
                            break;
                    }
                }
                while (reader.Read());
            }
            finally
            {
                builder.Close();
            }
        }