internal virtual string LookupNamespace(string prefix, bool atomizedNames) { switch (prefix) { case PrefixXmlns: return(nameTable.Get(XmlnsXmlns)); case PrefixXml: return(nameTable.Get(XmlnsXml)); case "": return(DefaultNamespace); case null: return(null); } for (int i = declPos; i >= 0; i--) { if (CompareString(decls [i].Prefix, prefix, atomizedNames) && decls [i].Uri != null /* null == flag for removed */) { return(decls [i].Uri); } } return(null); }
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; }
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; }
internal XmlElementList(XmlNode parent, string localName, string namespaceURI) : this(parent) { XmlNameTable nameTable = parent.Document.NameTable; this.asterisk = nameTable.Add("*"); this.localName = nameTable.Get(localName); this.namespaceURI = nameTable.Get(namespaceURI); if ((this.localName == null) || (this.namespaceURI == null)) { this.empty = true; this.atomized = false; this.localName = localName; this.namespaceURI = namespaceURI; } this.name = null; }
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; }
private XmlNameEntry GetInternal(string prefix, string local, string ns, bool atomic) { if (!atomic) { if (nameTable.Get(prefix) == null || nameTable.Get(local) == null || nameTable.Get(ns) == null) { return(null); } } dummy.Update(prefix, local, ns); return(table [dummy] as XmlNameEntry); }
// Gets the value of the attribute with the specified LocalName and NamespaceURI. public override string?GetAttribute(string name, string?namespaceURI) { namespaceURI = (namespaceURI == null) ? string.Empty : _coreReaderNameTable.Get(namespaceURI); string?atomizedName = _coreReaderNameTable.Get(name); ValidatingReaderNodeData attribute; for (int i = 0; i < _attributeCount; i++) { attribute = _attributeEvents[i]; if (Ref.Equal(attribute.LocalName, atomizedName) && Ref.Equal(attribute.Namespace, namespaceURI)) { return(attribute.RawValue); } } return(null); }
internal XmlElementList(XmlNode parent, string localName, string namespaceURI) : this(parent) { Debug.Assert(parent.Document != null); XmlNameTable nt = parent.Document.NameTable; Debug.Assert(nt != null); _asterisk = nt.Add("*"); _localName = nt.Get(localName); _namespaceURI = nt.Get(namespaceURI); if ((_localName == null) || (_namespaceURI == null)) { _empty = true; _atomized = false; _localName = localName; _namespaceURI = namespaceURI; } _name = null; }
private int FindAttribute(String name) { name = _nameTable.Get(name); if (name != null) { int count = _attributes.Count; for (int i = 0; i < count; i++) { if (Object.ReferenceEquals(name, ((XmlReader_XmlAttribute)_attributes[i]).Name)) { return(i); } } } return(-1); }
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; }
public static string NormalizeString(XmlNameTable nameTable, string s) { if (s == null) return s; string result = nameTable.Get(s); if (result == null) result = nameTable.Add(s); return result; }
/// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.RemoveNamespace"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public virtual void RemoveNamespace(string prefix, string uri) { if (uri == null) { throw new ArgumentNullException("uri"); } if (prefix == null) { throw new ArgumentNullException("prefix"); } prefix = nameTable.Get(prefix); uri = nameTable.Get(uri); if (prefix != null && uri != null) { for (int declIndex = decls.Length - 1; declIndex >= decls.Length - count; declIndex--) { NsDecl decl = (NsDecl)decls[declIndex]; if (Ref.Equal(decl.Prefix, prefix) && Ref.Equal(decl.Uri, uri)) { decl.Uri = null; } } } }
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; }
private void ValidateElement() { _nsManager.PushScope(); XmlElement elementNode = _currentNode as XmlElement; Debug.Assert(elementNode != null); XmlAttributeCollection attributes = elementNode.Attributes; XmlAttribute attr = null; //Find Xsi attributes that need to be processed before validating the element string xsiNil = null; string xsiType = null; for (int i = 0; i < attributes.Count; i++) { attr = attributes[i]; string objectNs = attr.NamespaceURI; string objectName = attr.LocalName; Debug.Assert(_nameTable.Get(attr.NamespaceURI) != null); Debug.Assert(_nameTable.Get(attr.LocalName) != null); if (Ref.Equal(objectNs, _nsXsi)) { if (Ref.Equal(objectName, _xsiType)) { xsiType = attr.Value; } else if (Ref.Equal(objectName, _xsiNil)) { xsiNil = attr.Value; } } else if (Ref.Equal(objectNs, _nsXmlNs)) { _nsManager.AddNamespace(attr.Prefix.Length == 0 ? string.Empty : attr.LocalName, attr.Value); } } _validator.ValidateElement(elementNode.LocalName, elementNode.NamespaceURI, _schemaInfo, xsiType, xsiNil, null, null); ValidateAttributes(elementNode); _validator.ValidateEndOfAttributes(_schemaInfo); //If element has children, drill down for (XmlNode child = elementNode.FirstChild; child != null; child = child.NextSibling) { ValidateNode(child); } //Validate end of element _currentNode = elementNode; //Reset current Node for validation call back _validator.ValidateEndElement(_schemaInfo); //Get XmlName, as memberType / validity might be set now if (_psviAugmentation) { elementNode.XmlName = _document.AddXmlName(elementNode.Prefix, elementNode.LocalName, elementNode.NamespaceURI, _schemaInfo); if (_schemaInfo.IsDefault) { //the element has a default value XmlText textNode = _document.CreateTextNode(_schemaInfo.SchemaElement.ElementDecl.DefaultValueRaw); elementNode.AppendChild(textNode); } } _nsManager.PopScope(); //Pop current namespace scope }
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; }
private void HandleSpecialColumn(DataColumn col, XmlNameTable nameTable, XmlNodeIdHashtable columns) { // if column name starts with xml, we encode it manualy 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 += col.ColumnName.Substring(1); if (nameTable.Get(tempColumnName) == null) { nameTable.Add(tempColumnName); } string columnNamespace = nameTable.Get(col.Namespace); XmlNodeIdentety idColumn = new XmlNodeIdentety(tempColumnName, columnNamespace); columns[idColumn] = col; }
// 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 _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; } } } } }
// This one is used while reading data with preloaded schema 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); // Attept to look up DataSet namespace // in the name table if (dsNamespace == null) { // Found ? dsNamespace = nameTable.Add(dataSet.Namespace); // 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); 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; } } } } }
private 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 if (columnLocalName == null) { // Not found? columnLocalName = nameTable.Add(_columnLocalName); // 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; }
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 }
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; }
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); }
// 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; }
private void BuildIdentityMap(XmlNameTable nameTable, DataTable dataTable) { ArrayList selfAndDescendants = this.GetSelfAndDescendants(dataTable); this.tableSchemaMap = new XmlNodeIdHashtable(selfAndDescendants.Count); foreach (DataTable table in selfAndDescendants) { 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; } } } } }