private void CreateElement( JsonReader reader, IXmlDocument document, IXmlNode currentNode, string elementName, XmlNamespaceManager manager, string elementPrefix, Dictionary <string, string> attributeNameValues) { IXmlElement element = this.CreateElement(elementName, document, elementPrefix, manager); currentNode.AppendChild((IXmlNode)element); if (attributeNameValues != null) { foreach (KeyValuePair <string, string> attributeNameValue in attributeNameValues) { string str = XmlConvert.EncodeName(attributeNameValue.Key); string prefix = MiscellaneousUtils.GetPrefix(attributeNameValue.Key); IXmlNode attribute = !string.IsNullOrEmpty(prefix) ? document.CreateAttribute(str, manager.LookupNamespace(prefix) ?? string.Empty, attributeNameValue.Value) : document.CreateAttribute(str, attributeNameValue.Value); element.SetAttributeNode(attribute); } } switch (reader.TokenType) { case JsonToken.Integer: case JsonToken.Float: case JsonToken.String: case JsonToken.Boolean: case JsonToken.Date: string xmlValue = this.ConvertTokenToXmlValue(reader); if (xmlValue == null) { break; } element.AppendChild(document.CreateTextNode(xmlValue)); break; case JsonToken.Null: break; case JsonToken.EndObject: manager.RemoveNamespace(string.Empty, manager.DefaultNamespace); break; default: manager.PushScope(); this.DeserializeNode(reader, document, manager, (IXmlNode)element); manager.PopScope(); manager.RemoveNamespace(string.Empty, manager.DefaultNamespace); break; } }
private void CallRequest(TagTestItem def, AttrBroadcasterFilter attr, CreatorIssuer state, string pred2, XmlNamespaceManager reference3, string asset4, Dictionary <string, string> token5) { //Discarded unreachable code: IL_0002 //IL_0003: Incompatible stack heights: 0 vs 1 InfoRequestStrategy infoRequestStrategy = FindIterator(pred2, attr, asset4, reference3); state._0001(infoRequestStrategy); if (token5 != null) { foreach (KeyValuePair <string, string> item in token5) { string text = XmlConvert.EncodeName(item.Key); string text2 = CustomerListAnnotation.CountIssuer(item.Key); CreatorIssuer key = (!SetterTest.StartReader(text2)) ? attr._0002(text, reference3.LookupNamespace(text2) ?? string.Empty, item.Value) : attr._0002(text, item.Value); infoRequestStrategy._0001(key); } } switch (def._0001()) { case WatcherComposer.Null: break; case WatcherComposer.Integer: case WatcherComposer.Float: case WatcherComposer.String: case WatcherComposer.Boolean: case WatcherComposer.Date: case WatcherComposer.Bytes: { string text3 = WriteRequest(def); if (text3 != null) { ((CreatorIssuer)infoRequestStrategy)._0001(attr._0002(text3)); } break; } case WatcherComposer.EndObject: reference3.RemoveNamespace(string.Empty, reference3.DefaultNamespace); break; default: reference3.PushScope(); ValidateIterator(def, attr, reference3, infoRequestStrategy); reference3.PopScope(); reference3.RemoveNamespace(string.Empty, reference3.DefaultNamespace); break; } }
private void CreateElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string elementName, XmlNamespaceManager manager, string elementPrefix, Dictionary <string, string> attributeNameValues) { IXmlElement newChild = this.CreateElement(elementName, document, elementPrefix, manager); currentNode.AppendChild(newChild); foreach (KeyValuePair <string, string> pair in attributeNameValues) { string qualifiedName = XmlConvert.EncodeName(pair.Key); string prefix = MiscellaneousUtils.GetPrefix(pair.Key); string text1 = manager.LookupNamespace(prefix); if (text1 == null) { } IXmlNode attribute = !string.IsNullOrEmpty(prefix) ? document.CreateAttribute(qualifiedName, string.Empty, pair.Value) : document.CreateAttribute(qualifiedName, pair.Value); newChild.SetAttributeNode(attribute); } if (((reader.TokenType == JsonToken.String) || (reader.TokenType == JsonToken.Integer)) || (((reader.TokenType == JsonToken.Float) || (reader.TokenType == JsonToken.Boolean)) || (reader.TokenType == JsonToken.Date))) { string text = this.ConvertTokenToXmlValue(reader); if (text != null) { newChild.AppendChild(document.CreateTextNode(text)); } } else if (reader.TokenType != JsonToken.Null) { if (reader.TokenType != JsonToken.EndObject) { manager.PushScope(); this.DeserializeNode(reader, document, manager, newChild); manager.PopScope(); } manager.RemoveNamespace(string.Empty, manager.DefaultNamespace); } }
private void CreateElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string elementName, XmlNamespaceManager manager, string elementPrefix, Dictionary <string, string> attributeNameValues) { IXmlElement xmlElement = this.CreateElement(elementName, document, elementPrefix, manager); currentNode.AppendChild(xmlElement); foreach (KeyValuePair <string, string> attributeNameValue in attributeNameValues) { string str = XmlConvert.EncodeName(attributeNameValue.Key); string prefix = MiscellaneousUtils.GetPrefix(attributeNameValue.Key); xmlElement.SetAttributeNode((!string.IsNullOrEmpty(prefix) ? document.CreateAttribute(str, manager.LookupNamespace(prefix) ?? string.Empty, attributeNameValue.Value) : document.CreateAttribute(str, attributeNameValue.Value))); } if (reader.TokenType == JsonToken.String || reader.TokenType == JsonToken.Integer || reader.TokenType == JsonToken.Float || reader.TokenType == JsonToken.Boolean || reader.TokenType == JsonToken.Date) { string xmlValue = this.ConvertTokenToXmlValue(reader); if (xmlValue != null) { xmlElement.AppendChild(document.CreateTextNode(xmlValue)); return; } } else if (reader.TokenType != JsonToken.Null) { if (reader.TokenType != JsonToken.EndObject) { manager.PushScope(); this.DeserializeNode(reader, document, manager, xmlElement); manager.PopScope(); } manager.RemoveNamespace(string.Empty, manager.DefaultNamespace); } }
public void Dispose() { foreach (var ns in _namespaces) { _nsMan.RemoveNamespace(ns.Name, ns.Namespace); } }
// Check the "HasNamespace" method. public void TestXmlNamespaceManagerHas() { NameTable table = new NameTable(); XmlNamespaceManager ns = new XmlNamespaceManager(table); Assert("Has (1)", ns.HasNamespace("xml")); Assert("Has (2)", ns.HasNamespace("xmlns")); Assert("Has (3)", ns.HasNamespace("")); Assert("Has (4)", !ns.HasNamespace("foo")); ns.AddNamespace("foo", "uri"); Assert("Has (5)", ns.HasNamespace("xml")); Assert("Has (6)", ns.HasNamespace("xmlns")); Assert("Has (7)", ns.HasNamespace("")); Assert("Has (8)", ns.HasNamespace("foo")); ns.PushScope(); ns.AddNamespace("bar", "uri2"); Assert("Has (9)", ns.HasNamespace("xml")); Assert("Has (10)", ns.HasNamespace("xmlns")); Assert("Has (11)", ns.HasNamespace("")); Assert("Has (12)", ns.HasNamespace("foo")); Assert("Has (13)", ns.HasNamespace("bar")); ns.PopScope(); Assert("Has (14)", ns.HasNamespace("xml")); Assert("Has (15)", ns.HasNamespace("xmlns")); Assert("Has (16)", ns.HasNamespace("")); Assert("Has (17)", ns.HasNamespace("foo")); Assert("Has (18)", !ns.HasNamespace("bar")); ns.RemoveNamespace("foo", "uri"); Assert("Has (19)", ns.HasNamespace("xml")); Assert("Has (20)", ns.HasNamespace("xmlns")); Assert("Has (21)", ns.HasNamespace("")); Assert("Has (22)", !ns.HasNamespace("foo")); Assert("Has (23)", !ns.HasNamespace("bar")); ns.RemoveNamespace("", ""); Assert("Has (24)", ns.HasNamespace("xml")); Assert("Has (25)", ns.HasNamespace("xmlns")); Assert("Has (26)", ns.HasNamespace("")); Assert("Has (27)", !ns.HasNamespace("foo")); Assert("Has (28)", !ns.HasNamespace("bar")); Assert("Has (29)", !ns.HasNamespace(null)); }
public override void Process(XsltDebuggerConsole run, string [] args) { XmlNamespaceManager n = run.debugger.NamespaceManager; string prefix = args.Length == 3 ? args [2] : String.Empty; string ns = n.LookupNamespace(prefix); if (ns == null) { throw new XsltDebuggerException("Specified namespace prefix is not defined."); } n.RemoveNamespace(prefix, ns); Console.WriteLine("Removed xmlns {0}->{1}", prefix, ns); }
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)); }
// Check the "RemoveNamespace" method. public void TestXmlNamespaceManagerRemove() { NameTable table = new NameTable(); XmlNamespaceManager ns = new XmlNamespaceManager(table); // Test the exception behaviour. try { ns.AddNamespace(null, "uri"); Fail("Remove (1)"); } catch (ArgumentNullException) { // Success } try { ns.AddNamespace("prefix", null); Fail("Remove (2)"); } catch (ArgumentNullException) { // Success } // Cannot remove standard namespaces. ns.RemoveNamespace ("xml", "http://www.w3.org/XML/1998/namespace"); AssertEquals("Remove (3)", "http://www.w3.org/XML/1998/namespace", ns.LookupNamespace("xml")); ns.RemoveNamespace ("xmlns", "http://www.w3.org/2000/xmlns/"); AssertEquals("Remove (3)", "http://www.w3.org/2000/xmlns/", ns.LookupNamespace("xmlns")); // Add and remove a particular namespace. ns.AddNamespace("foo", "uri"); ns.RemoveNamespace("foo", "uri"); AssertNull("Remove (4)", ns.LookupNamespace("foo")); // Make sure that we cannot remove namespaces in parent scopes. ns.AddNamespace("foo", "uri"); ns.PushScope(); ns.RemoveNamespace("foo", "uri"); AssertEquals("Remove (5)", "uri", ns.LookupNamespace("foo")); // Try removing a namespace with the wrong URI or prefix. ns.AddNamespace("foo", "uri2"); ns.RemoveNamespace("foo", "uri"); AssertEquals("Remove (6)", "uri2", ns.LookupNamespace("foo")); ns.RemoveNamespace("foo2", "uri"); AssertEquals("Remove (7)", "uri2", ns.LookupNamespace("foo")); }
private string GetOrganization(XmlNode childrenNode, XmlNamespaceManager nsmgr, Dataset dataset, DatasetFile datasetFile = null) { string organization = ""; if ((dataset != null && dataset.Url.Contains("miljodirektoratet")) || (datasetFile != null && datasetFile.Url.Contains("miljodirektoratet"))) { nsmgr.RemoveNamespace("gn", "http://geonorge.no/Atom"); nsmgr.AddNamespace("gn", "http://geonorge.no/geonorge"); } var organizationGN = childrenNode.SelectSingleNode("a:author/gn:organisation", nsmgr); if (organizationGN != null) { organization = organizationGN.InnerXml; } else if (childrenNode.SelectSingleNode("a:author/a:name", nsmgr) != null) { organization = childrenNode.SelectSingleNode("a:author/a:name", nsmgr).InnerXml; } else { organization = "Kartverket"; } if (dataset != null && string.IsNullOrEmpty(dataset.Organization) && dataset.Url.Contains("ngu.no")) { organization = "Norges geologiske undersøkelse"; } else if (dataset != null && string.IsNullOrEmpty(dataset.Organization) && dataset.Url.Contains("nibio.no")) { organization = "Norsk institutt for bioøkonomi"; } if (datasetFile != null && string.IsNullOrEmpty(datasetFile.Organization) && datasetFile.Url.Contains("ngu.no")) { organization = "Norges geologiske undersøkelse"; } else if (datasetFile != null && string.IsNullOrEmpty(datasetFile.Organization) && datasetFile.Url.Contains("nibio.no")) { organization = "Norsk institutt for bioøkonomi"; } return(organization); }
private XmlNamespaceManager getNamespaces(XmlReader xmlReader, XPathNavigator xNav) { var resolver = new XmlNamespaceManager(xmlReader.NameTable); IDictionary <string, string> localNamespaces = null; while (xNav.MoveToFollowing(XPathNodeType.Element)) { localNamespaces = xNav.GetNamespacesInScope(XmlNamespaceScope.Local); foreach (var localNamespace in localNamespaces) { resolver.RemoveNamespace(localNamespace.Key, localNamespace.Value); var prefix = string.IsNullOrEmpty(localNamespace.Key) ? DEFAULT : localNamespace.Key; resolver.AddNamespace(prefix, localNamespace.Value); } } return(resolver); }
// Token: 0x06001033 RID: 4147 RVA: 0x000516F8 File Offset: 0x0004F8F8 private void smethod_2970(Class_285 arg_0, Class_389 arg_1, Class_387 arg_2, string str_0, XmlNamespaceManager arg_3) { if (string.IsNullOrEmpty(str_0)) { throw new Class_417("XmlNodeConverter cannot convert JSON with an empty property name to XML."); } Dictionary <string, string> dictionary = this.cmethod_2974(arg_0, arg_3); string prefix = Class_513.GetPrefix(str_0); if (str_0.StartsWith('@')) { string text = str_0.Substring(1); string text2 = arg_0.prop_10.ToString(); string prefix2 = Class_513.GetPrefix(text); Class_387 arg_4 = (!string.IsNullOrEmpty(prefix2)) ? arg_1.tmethod_2842(text, arg_3.LookupNamespace(prefix2), text2) : arg_1.xmethod_2841(text, text2); ((Class_391)arg_2).kmethod_2857(arg_4); return; } Class_391 class_ = this.kmethod_2977(str_0, arg_1, prefix, arg_3); arg_2.kmethod_2817(class_); foreach (KeyValuePair <string, string> keyValuePair in dictionary) { string prefix3 = Class_513.GetPrefix(keyValuePair.Key); Class_387 arg_5 = (!string.IsNullOrEmpty(prefix3)) ? arg_1.tmethod_2842(keyValuePair.Key, arg_3.LookupNamespace(prefix3), keyValuePair.Value) : arg_1.xmethod_2841(keyValuePair.Key, keyValuePair.Value); class_.kmethod_2857(arg_5); } if (arg_0.prop_9 == Class_508.String || arg_0.prop_9 == Class_508.Integer || arg_0.prop_9 == Class_508.Float || arg_0.prop_9 == Class_508.Boolean || arg_0.prop_9 == Class_508.Date) { class_.kmethod_2817(arg_1.tmethod_2832(this.xmethod_2971(arg_0))); return; } if (arg_0.prop_9 == Class_508.Null) { return; } if (arg_0.prop_9 != Class_508.EndObject) { arg_3.PushScope(); this.lmethod_2978(arg_0, arg_1, arg_3, class_); arg_3.PopScope(); } arg_3.RemoveNamespace(string.Empty, arg_3.DefaultNamespace); }
//[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; }
// Check the "RemoveNamespace" method. public void TestXmlNamespaceManagerRemove() { NameTable table = new NameTable(); XmlNamespaceManager ns = new XmlNamespaceManager(table); // Test the exception behaviour. try { ns.AddNamespace(null, "uri"); Fail("Remove (1)"); } catch(ArgumentNullException) { // Success } try { ns.AddNamespace("prefix", null); Fail("Remove (2)"); } catch(ArgumentNullException) { // Success } // Cannot remove standard namespaces. ns.RemoveNamespace ("xml", "http://www.w3.org/XML/1998/namespace"); AssertEquals("Remove (3)", "http://www.w3.org/XML/1998/namespace", ns.LookupNamespace("xml")); ns.RemoveNamespace ("xmlns", "http://www.w3.org/2000/xmlns/"); AssertEquals("Remove (3)", "http://www.w3.org/2000/xmlns/", ns.LookupNamespace("xmlns")); // Add and remove a particular namespace. ns.AddNamespace("foo", "uri"); ns.RemoveNamespace("foo", "uri"); AssertNull("Remove (4)", ns.LookupNamespace("foo")); // Make sure that we cannot remove namespaces in parent scopes. ns.AddNamespace("foo", "uri"); ns.PushScope(); ns.RemoveNamespace("foo", "uri"); AssertEquals("Remove (5)", "uri", ns.LookupNamespace("foo")); // Try removing a namespace with the wrong URI or prefix. ns.AddNamespace("foo", "uri2"); ns.RemoveNamespace("foo", "uri"); AssertEquals("Remove (6)", "uri2", ns.LookupNamespace("foo")); ns.RemoveNamespace("foo2", "uri"); AssertEquals("Remove (7)", "uri2", ns.LookupNamespace("foo")); }
// Check the "HasNamespace" method. public void TestXmlNamespaceManagerHas() { NameTable table = new NameTable(); XmlNamespaceManager ns = new XmlNamespaceManager(table); Assert("Has (1)", ns.HasNamespace("xml")); Assert("Has (2)", ns.HasNamespace("xmlns")); Assert("Has (3)", ns.HasNamespace("")); Assert("Has (4)", !ns.HasNamespace("foo")); ns.AddNamespace("foo", "uri"); Assert("Has (5)", ns.HasNamespace("xml")); Assert("Has (6)", ns.HasNamespace("xmlns")); Assert("Has (7)", ns.HasNamespace("")); Assert("Has (8)", ns.HasNamespace("foo")); ns.PushScope(); ns.AddNamespace("bar", "uri2"); Assert("Has (9)", ns.HasNamespace("xml")); Assert("Has (10)", ns.HasNamespace("xmlns")); Assert("Has (11)", ns.HasNamespace("")); Assert("Has (12)", ns.HasNamespace("foo")); Assert("Has (13)", ns.HasNamespace("bar")); ns.PopScope(); Assert("Has (14)", ns.HasNamespace("xml")); Assert("Has (15)", ns.HasNamespace("xmlns")); Assert("Has (16)", ns.HasNamespace("")); Assert("Has (17)", ns.HasNamespace("foo")); Assert("Has (18)", !ns.HasNamespace("bar")); ns.RemoveNamespace("foo", "uri"); Assert("Has (19)", ns.HasNamespace("xml")); Assert("Has (20)", ns.HasNamespace("xmlns")); Assert("Has (21)", ns.HasNamespace("")); Assert("Has (22)", !ns.HasNamespace("foo")); Assert("Has (23)", !ns.HasNamespace("bar")); ns.RemoveNamespace("", ""); Assert("Has (24)", ns.HasNamespace("xml")); Assert("Has (25)", ns.HasNamespace("xmlns")); Assert("Has (26)", ns.HasNamespace("")); Assert("Has (27)", !ns.HasNamespace("foo")); Assert("Has (28)", !ns.HasNamespace("bar")); Assert("Has (29)", !ns.HasNamespace(null)); }
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); } } }
/// <summary> /// Remove the namespace. /// </summary> /// <param name="prefix">Prefix.</param> /// <param name="uri">URI.</param> public void RemoveNamespace(string prefix, string uri) { _xmlNamespaceManager.RemoveNamespace(prefix, uri); }
public void RemoveNamespace(string prefix, string ns) { _mgr.RemoveNamespace(prefix, ns); }