当前位置: 首页>>代码示例>>C#>>正文


C# XmlNamespaceManager.RemoveNamespace方法代码示例

本文整理汇总了C#中System.Xml.XmlNamespaceManager.RemoveNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNamespaceManager.RemoveNamespace方法的具体用法?C# XmlNamespaceManager.RemoveNamespace怎么用?C# XmlNamespaceManager.RemoveNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlNamespaceManager的用法示例。


在下文中一共展示了XmlNamespaceManager.RemoveNamespace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Strip

        public XmlNode Strip(XmlNode documentElement)
        {
            var namespaceManager = new XmlNamespaceManager(documentElement.OwnerDocument.NameTable);
            foreach (var nspace in namespaceManager.GetNamespacesInScope(XmlNamespaceScope.All))
            {
                namespaceManager.RemoveNamespace(nspace.Key, nspace.Value);
            }

            return documentElement;
        }
开发者ID:nadavdrewe,项目名称:extension_railgunit_com,代码行数:10,代码来源:XmlStripper.cs

示例2: ReadElement

        private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
        {
            if (string.IsNullOrEmpty(propertyName))
                throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");

            Dictionary<string, string> attributeNameValues = ReadAttributeElements(reader, manager);

            string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

            if (propertyName.StartsWith('@'))
            {
                string attributeName = propertyName.Substring(1);
                string attributeValue = reader.Value.ToString();

                string attributePrefix = MiscellaneousUtils.GetPrefix(attributeName);

                IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
                    ? document.CreateAttribute(attributeName, manager.LookupNamespace(attributePrefix), attributeValue)
                    : document.CreateAttribute(attributeName, attributeValue);

                ((IXmlElement)currentNode).SetAttributeNode(attribute);
            }
            else
            {
                IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager);

                currentNode.AppendChild(element);

                // add attributes to newly created element
                foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
                {
                    string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);

                    IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
                        ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix), nameValue.Value)
                        : document.CreateAttribute(nameValue.Key, nameValue.Value);

                    element.SetAttributeNode(attribute);
                }

                if (reader.TokenType == JsonToken.String
                    || reader.TokenType == JsonToken.Integer
                    || reader.TokenType == JsonToken.Float
                    || reader.TokenType == JsonToken.Boolean
                    || reader.TokenType == JsonToken.Date)
                {
                    element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
                }
                else if (reader.TokenType == JsonToken.Null)
                {
                    // empty element. do nothing
                }
                else
                {
                    // finished element will have no children to deserialize
                    if (reader.TokenType != JsonToken.EndObject)
                    {
                        manager.PushScope();
                        DeserializeNode(reader, document, manager, element);
                        manager.PopScope();
                    }

                    manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
                }
            }
        }
开发者ID:Henry-T,项目名称:UnityPG,代码行数:66,代码来源:XmlNodeConverter.cs

示例3: CreateElement

        private void CreateElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string elementName, XmlNamespaceManager manager, string elementPrefix, Dictionary<string, string> attributeNameValues)
        {
            IXmlElement element = CreateElement(elementName, document, elementPrefix, manager);

            currentNode.AppendChild(element);

            // add attributes to newly created element
            foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
            {
                string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);

                IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
                    ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix) ?? string.Empty, nameValue.Value)
                    : document.CreateAttribute(nameValue.Key, nameValue.Value);

                element.SetAttributeNode(attribute);
            }

            if (reader.TokenType == JsonToken.String
                || reader.TokenType == JsonToken.Integer
                || reader.TokenType == JsonToken.Float
                || reader.TokenType == JsonToken.Boolean
                || reader.TokenType == JsonToken.Date)
            {
                element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
            }
            else if (reader.TokenType == JsonToken.Null)
            {
                // empty element. do nothing
            }
            else
            {
                // finished element will have no children to deserialize
                if (reader.TokenType != JsonToken.EndObject)
                {
                    manager.PushScope();
                    DeserializeNode(reader, document, manager, element);
                    manager.PopScope();
                }

                manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
            }
        }
开发者ID:b-bot-110,项目名称:Newtonsoft.Json,代码行数:43,代码来源:XmlNodeConverter.cs

示例4: AddPushPopRemove

		public void AddPushPopRemove ()
		{
			XmlNamespaceManager nsmgr =
				new XmlNamespaceManager (new NameTable ());
			string ns = nsmgr.NameTable.Add ("urn:foo");
			nsmgr.AddNamespace ("foo", ns);
			Assert.AreEqual ("foo", nsmgr.LookupPrefix (ns));
			nsmgr.PushScope ();
			Assert.AreEqual ("foo", nsmgr.LookupPrefix (ns));
			nsmgr.PopScope ();
			Assert.AreEqual ("foo", nsmgr.LookupPrefix (ns));
			nsmgr.RemoveNamespace ("foo", ns);
			Assert.IsNull (nsmgr.LookupPrefix (ns));
		}
开发者ID:Profit0004,项目名称:mono,代码行数:14,代码来源:XmlNamespaceManagerTests.cs

示例5: ReadElement

 // Token: 0x060006E4 RID: 1764
 // RVA: 0x000382C8 File Offset: 0x000364C8
 private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
 {
     if (string.IsNullOrEmpty(propertyName))
     {
         throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");
     }
     Dictionary<string, string> dictionary = this.ReadAttributeElements(reader, manager);
     string prefix = MiscellaneousUtils.GetPrefix(propertyName);
     if (StringUtils.StartsWith(propertyName, '@'))
     {
         string text = propertyName.Substring(1);
         string value = reader.Value.ToString();
         string prefix2 = MiscellaneousUtils.GetPrefix(text);
         IXmlNode attributeNode = (!string.IsNullOrEmpty(prefix2)) ? document.CreateAttribute(text, manager.LookupNamespace(prefix2), value) : document.CreateAttribute(text, value);
         ((IXmlElement)currentNode).SetAttributeNode(attributeNode);
         return;
     }
     IXmlElement xmlElement = this.CreateElement(propertyName, document, prefix, manager);
     currentNode.AppendChild(xmlElement);
     foreach (KeyValuePair<string, string> current in dictionary)
     {
         string prefix3 = MiscellaneousUtils.GetPrefix(current.Key);
         IXmlNode attributeNode2 = (!string.IsNullOrEmpty(prefix3)) ? document.CreateAttribute(current.Key, manager.LookupNamespace(prefix3), current.Value) : document.CreateAttribute(current.Key, current.Value);
         xmlElement.SetAttributeNode(attributeNode2);
     }
     if (reader.TokenType != JsonToken.String && reader.TokenType != JsonToken.Integer && reader.TokenType != JsonToken.Float && reader.TokenType != JsonToken.Boolean)
     {
         if (reader.TokenType != JsonToken.Date)
         {
             if (reader.TokenType == JsonToken.Null)
             {
                 return;
             }
             if (reader.TokenType != JsonToken.EndObject)
             {
                 manager.PushScope();
                 this.DeserializeNode(reader, document, manager, xmlElement);
                 manager.PopScope();
             }
             manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
             return;
         }
     }
     xmlElement.AppendChild(document.CreateTextNode(this.ConvertTokenToXmlValue(reader)));
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:47,代码来源:XmlNodeConverter.cs

示例6: CheckNode

        private void CheckNode(XmlNode node2, XmlDocument doc1, XmlNode currentparentnode)
        {
            //achtung: wenn ReplaceExistingNode da ist, dann wird das erste auftreten einer Node mit gleichem Namen eine komplette ersetzung durchgeführt
            //speziell für DocumentTemplates
          //ist die node2 im doc1 enthalten???

          //erstelle ein Xslt für die node
          string xslt2 = FindXPath(node2);

          string xslt2b = GetXPathToNode(node2);

          XmlNode parentnode = null;

          if (xslt2 != "")
          {
              XmlNamespaceManager featurensmgr = new XmlNamespaceManager(doc1.NameTable);
              foreach (string key in namespaces.Keys)
              {
                  featurensmgr.AddNamespace(key, namespaces[key]);
              }

              XmlNodeList foundnodes = doc1.SelectNodes(xslt2, featurensmgr);
              

              //ich brauche den attributecount, aber ohne xmlns, 
              int attribcount = 0;
              foreach (XmlAttribute attrib in node2.Attributes)
              {
                  if (attrib.Name != "xmlns")
                  {
                      attribcount++;
                  }
              }

              if ((foundnodes.Count == 1) && (attribcount == 0))
              {
                  //wenn nur 1 node gefunden und node2 hat gar keine Attribute, dann nehmen wir diese
                  //dann will man vermutlich mergen
                  parentnode = foundnodes[0];
              }
              else
              {
                  foreach (XmlNode foundnode in foundnodes)
                  {
                      //die gefundene Node könnte aber auch mehr attribute haben, als 
                      //im xpath angegeben. deshalb hier überprüfung, ob der Attribute-Count
                      //gleich ist. Wenn nicht, nehmen wir die nächste Node, die passen könnte
                      if (foundnode.Attributes.Count == node2.Attributes.Count)
                      {
                          parentnode = foundnode;
                      }
                  }
              }
          }

          if (parentnode == null)
          {
            //meine neue node gibt es noch nicht
            //also rein damit und nicht weitermachen
            //namespaces entfernen vor dem Einfügen, da die Namespaces 
            //mit dem parent gleich sind

            XmlNamespaceManager xnm = new XmlNamespaceManager(node2.OwnerDocument.NameTable);
            xnm.RemoveNamespace(node2.Prefix, node2.NamespaceURI);

            XmlDocumentFragment docFrag = doc1.CreateDocumentFragment();
            docFrag.InnerXml = node2.OuterXml;
            currentparentnode.AppendChild(docFrag);
          }
          else
          {
            //die gleiche Node habe ich gefunden, 
            //ich brauche also nichts hineinmachen
            //jetzt hier die Kinder prüfe
            foreach (XmlNode node2a in node2.ChildNodes)
            {
              CheckNode(node2a, doc1, parentnode);
            }
          }
        }
开发者ID:manuel11g,项目名称:SharePoint-Software-Factory,代码行数:80,代码来源:AddXmlToItemAction.cs

示例7: v5

 //[Variation("nsm.AddNamespace(null, 'ns1')", Param = 1)]
 //[Variation("nsm.RemoveNamespace(null, 'ns1')", Param = 2)]
 public int v5()
 {
     int param = (int)CurVariation.Param;
     string xml = @"<a>p:foo</a>";
     ReloadSource(new StringReader(xml));
     DataReader.Read(); DataReader.Read();
     XmlNamespaceManager nsm = new XmlNamespaceManager(DataReader.NameTable);
     try
     {
         if (param == 1)
             nsm.AddNamespace(null, "ns1");
         else
             nsm.RemoveNamespace(null, "ns1");
     }
     catch (ArgumentNullException)
     {
         try
         {
             if (param == 1)
                 nsm.AddNamespace(null, "ns1");
             else
                 nsm.RemoveNamespace(null, "ns1");
         }
         catch (ArgumentNullException) { return TEST_PASS; }
     }
     finally
     {
         DataReader.Close();
     }
     return TEST_FAIL;
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:33,代码来源:ErrorCondition.cs

示例8: ReadElement

        private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
        {
            if (string.IsNullOrEmpty(propertyName)) throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");

            var attributeNameValues = ReadAttributeElements(reader, manager);
            var elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

            if (propertyName.StartsWith('@'))
            {
                var attributeName = propertyName.Substring(1);
                var attributeValue = reader.Value.ToString();
                var attributePrefix = MiscellaneousUtils.GetPrefix(attributeName);
                var attribute = (!string.IsNullOrEmpty(attributePrefix)) ? document.CreateAttribute(attributeName, manager.LookupNamespace(attributePrefix), attributeValue) : document.CreateAttribute(attributeName, attributeValue);
                ((IXmlElement) currentNode).SetAttributeNode(attribute);
            }
            else
            {
                var element = CreateElement(propertyName, document, elementPrefix, manager);

                currentNode.AppendChild(element);

                // add attributes to newly created element
                foreach (var nameValue in attributeNameValues)
                {
                    var attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);
                    var attribute = (!string.IsNullOrEmpty(attributePrefix)) ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix) ?? string.Empty, nameValue.Value) : document.CreateAttribute(nameValue.Key, nameValue.Value);
                    element.SetAttributeNode(attribute);
                }

                switch (reader.TokenType)
                {
                    case JsonToken.Date:
                    case JsonToken.Boolean:
                    case JsonToken.Float:
                    case JsonToken.Integer:
                    case JsonToken.String:
                        element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
                        break;
                    case JsonToken.Null:
                        break;
                    default:
                        if (reader.TokenType != JsonToken.EndObject)
                        {
                            manager.PushScope();
                            DeserializeNode(reader, document, manager, element);
                            manager.PopScope();
                        }
                        manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
                        break;
                }
            }
        }
开发者ID:sat1582,项目名称:CODEFramework,代码行数:52,代码来源:XmlNodeConverter.cs


注:本文中的System.Xml.XmlNamespaceManager.RemoveNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。