public void PopScopeMustKeepAddedInScope()
 {
     namespaceManager = new XmlNamespaceManager(new NameTable()); // clear
     namespaceManager.AddNamespace("foo", "urn:foo");             // 0
     namespaceManager.AddNamespace("bar", "urn:bar");             // 0
     namespaceManager.PushScope();                                // 1
     namespaceManager.PushScope();                                // 2
     namespaceManager.PopScope();                                 // 2
     namespaceManager.PopScope();                                 // 1
     namespaceManager.PopScope();                                 // 0
     Assert.AreEqual("urn:foo", namespaceManager.LookupNamespace("foo"));
     Assert.AreEqual("urn:bar", namespaceManager.LookupNamespace("bar"));
 }
        private void PushParentNamespaces(IXmlNode node, XmlNamespaceManager manager)
        {
            List <IXmlNode> list    = null;
            IXmlNode        xmlNode = node;

            while ((xmlNode = xmlNode.ParentNode) != null)
            {
                if (xmlNode.NodeType == XmlNodeType.Element)
                {
                    if (list == null)
                    {
                        list = new List <IXmlNode>();
                    }
                    list.Add(xmlNode);
                }
            }
            if (list == null)
            {
                return;
            }
            list.Reverse();
            foreach (IXmlNode item in list)
            {
                manager.PushScope();
                foreach (IXmlNode attribute in item.Attributes)
                {
                    if (attribute.NamespaceURI == "http://www.w3.org/2000/xmlns/" && attribute.LocalName != "xmlns")
                    {
                        manager.AddNamespace(attribute.LocalName, attribute.Value);
                    }
                }
            }
        }
Example #3
0
        private static List <X509Certificate2> GetX509Certificate2FromADMetadataEndpoint()
        {
            List <X509Certificate2> certs     = new List <X509Certificate2>();
            XPathDocument           xmlReader = new XPathDocument(Configuration.MetadataUri);
            XPathNavigator          navigator = xmlReader.CreateNavigator();
            XmlNamespaceManager     manager   = new XmlNamespaceManager(navigator.NameTable);

            manager.AddNamespace("", "urn:oasis:names:tc:SAML:2.0:metadata");
            manager.AddNamespace("ns1", "urn:oasis:names:tc:SAML:2.0:metadata");
            manager.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
            manager.PushScope();

            //Reading all certs since AD periodically do cert rollover
            XPathNodeIterator nodes =
                navigator.Select(
                    "//ns1:EntityDescriptor/ns1:RoleDescriptor/ns1:KeyDescriptor[@use='signing']/ds:KeyInfo/ds:X509Data/ds:X509Certificate",
                    manager);

            while (nodes.MoveNext())
            {
                XPathNavigator nodesNavigator = nodes.Current;
                //Cert body is base64 encoded in metadata doc
                certs.Add(new X509Certificate2(Convert.FromBase64String(nodesNavigator.InnerXml)));
            }


            return(certs);
        }
        // Note that this must be done *before* filtering nodes out
        // by context node list.
        private void FillMissingPrefixes(XmlNode n, XmlNamespaceManager nsmgr, ArrayList tmpList)
        {
            if (n.Prefix.Length == 0 && propagatedNss != null)
            {
                foreach (DictionaryEntry de in propagatedNss)
                {
                    if ((string)de.Value == n.NamespaceURI)
                    {
                        n.Prefix = (string)de.Key;
                        break;
                    }
                }
            }

            if (n.NodeType == XmlNodeType.Element && ((XmlElement)n).HasAttributes)
            {
                foreach (XmlAttribute a in n.Attributes)
                {
                    if (a.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                    {
                        nsmgr.AddNamespace(a.Prefix.Length == 0 ? String.Empty : a.LocalName, a.Value);
                    }
                }
                nsmgr.PushScope();
            }

            if (n.NamespaceURI.Length > 0 && nsmgr.LookupPrefix(n.NamespaceURI) == null)
            {
                tmpList.Add(CreateXmlns(n));
            }

            if (n.NodeType == XmlNodeType.Element && ((XmlElement)n).HasAttributes)
            {
                foreach (XmlAttribute a in n.Attributes)
                {
                    if (a.NamespaceURI.Length > 0 && nsmgr.LookupNamespace(a.Prefix) == null)
                    {
                        tmpList.Add(CreateXmlns(a));
                    }
                }
            }

            foreach (XmlAttribute a in tmpList)
            {
                ((XmlElement)n).SetAttributeNode(a);
            }
            tmpList.Clear();

            if (n.HasChildNodes)
            {
                for (XmlNode c = n.FirstChild; c != null; c = c.NextSibling)
                {
                    if (c.NodeType == XmlNodeType.Element)
                    {
                        FillMissingPrefixes(c, nsmgr, tmpList);
                    }
                }
            }
            nsmgr.PopScope();
        }
Example #5
0
        private void AssetRequest(CreatorIssuer var1, XmlNamespaceManager cust)
        {
            //Discarded unreachable code: IL_0002
            //IL_0003: Incompatible stack heights: 0 vs 1
            List <CreatorIssuer> list          = null;
            CreatorIssuer        creatorIssuer = var1;

            while ((creatorIssuer = creatorIssuer._0001()) != null)
            {
                if (creatorIssuer._0001() == XmlNodeType.Element)
                {
                    if (list == null)
                    {
                        list = new List <CreatorIssuer>();
                    }
                    list.Add(creatorIssuer);
                }
            }
            if (list != null)
            {
                list.Reverse();
                foreach (CreatorIssuer item in list)
                {
                    cust.PushScope();
                    foreach (CreatorIssuer item2 in item._0002())
                    {
                        if (item2._0003() == "http://www.w3.org/2000/xmlns/" && item2._0001() != "xmlns")
                        {
                            cust.AddNamespace(item2._0001(), item2._0002());
                        }
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Get YouTube thumbnail of the video with specified ID
        /// </summary>
        /// <param name="id">Id of the video to get thumbnail of</param>
        /// <returns>BitmapSource of the preview</returns>
        internal static BitmapSource GetThumbBitmapFromYT(string id)
        {
            XmlDocument doc = new XmlDocument();

            XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);

            doc.Load("http://gdata.youtube.com/feeds/api/videos/" + id);

            ns.AddNamespace("", "http://www.w3.org/2005/Atom");
            ns.AddNamespace("media", "http://search.yahoo.com/mrss/");
            ns.PushScope();

            XmlElement  root = doc.DocumentElement;
            XmlNodeList list = root.ChildNodes;

            string videoThumbUrl;

            foreach (XmlNode node in list)
            {
                if (node.Name == "media:group")
                {
                    XmlNode thumbnail = node.SelectSingleNode("media:thumbnail", ns);
                    videoThumbUrl = thumbnail.Attributes["url"].Value;

                    return(Utils.GetImage(new Uri(videoThumbUrl)));
                }
            }

            return(null);
        }
Example #7
0
        /// <summary>
        /// See <see cref="XmlReader.Read"/>.
        /// </summary>
        public override bool Read()
        {
            bool read = base.Read();

            if (base.NodeType == XmlNodeType.Element)
            {
                nsManager.PushScope();
                for (bool go = base.BaseReader.MoveToFirstAttribute(); go; go = base.BaseReader.MoveToNextAttribute())
                {
                    if (base.BaseReader.NamespaceURI == xmlNsNamespace)
                    {
                        string prefix = GetNamespacePrefix();

                        // Only push if it's not already defined.
                        if (nsManager.LookupNamespace(prefix) == null)
                        {
                            nsManager.AddNamespace(prefix, Value);
                        }
                    }
                }

                // If it had attributes, we surely moved through all of them searching for namespaces
                if (base.BaseReader.HasAttributes)
                {
                    base.BaseReader.MoveToElement();
                }
            }
            else if (base.NodeType == XmlNodeType.EndElement)
            {
                nsManager.PopScope();
            }

            return(read);
        }
        /// <summary>
        /// Gets the X path name and push context.
        /// </summary>
        /// <param name="nmgr">The NMGR.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        private string GetXPathNameAndPushContext(XmlNamespaceManager nmgr, XmlNode node)
        {
            switch (node.NodeType)
            {
            case XmlNodeType.Comment:
                return("/comment()");

            case XmlNodeType.Document:
                return("/");

            case XmlNodeType.ProcessingInstruction:
                return("/processing-instruction()");

            case XmlNodeType.CDATA:
            case XmlNodeType.Text:
                return("/text()");

            default:
                if (node.NamespaceURI != String.Empty)
                {
                    string prefix = node.Prefix;
                    if (prefix == String.Empty)
                    {
                        prefix = String.Format("prefix{0}", prefixSequence);
                    }
                    nmgr.PushScope();
                    prefixSequence++;
                    nmgr.AddNamespace(prefix, node.NamespaceURI);
                    return(String.Concat('/', prefix, ':', node.LocalName));
                }
                return(String.Concat('/', node.LocalName));
            }
        }
        public override bool Read()
        {
            var read = base.Read();

            switch (base.NodeType)
            {
            case XmlNodeType.Element:
                _nsManager.PushScope();
                for (var go = BaseReader.MoveToFirstAttribute(); go; go = BaseReader.MoveToNextAttribute())
                {
                    if (BaseReader.NamespaceURI != _xmlNsNamespace)
                    {
                        continue;
                    }
                    var prefix = GetNamespacePrefix();

                    // Only push if it's not already defined.
                    if (_nsManager.LookupNamespace(prefix) == null)
                    {
                        _nsManager.AddNamespace(prefix, Value);
                    }
                }
                if (BaseReader.HasAttributes)
                {
                    BaseReader.MoveToElement();
                }
                break;

            case XmlNodeType.EndElement:
                _nsManager.PopScope();
                break;
            }

            return(read);
        }
Example #10
0
        private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
        {
            Dictionary <string, string> attributeNameValues = ReadAttributeElements(reader, manager);

            string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

            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)
            {
                element.AppendChild(document.CreateTextNode(reader.Value.ToString()));
            }
            else if (reader.TokenType == JsonToken.Integer)
            {
                element.AppendChild(document.CreateTextNode(XmlConvert.ToString((long)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Float)
            {
                element.AppendChild(document.CreateTextNode(XmlConvert.ToString((double)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Boolean)
            {
                element.AppendChild(document.CreateTextNode(XmlConvert.ToString((bool)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Date)
            {
                DateTime d = (DateTime)reader.Value;
                element.AppendChild(document.CreateTextNode(XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind))));
            }
            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();
                }
            }
        }
Example #11
0
        private void PushParentNamespaces(IXmlNode node, XmlNamespaceManager manager)
        {
            List <IXmlNode> list = null;
            IXmlNode        item = node;

            while ((item = item.ParentNode) != null)
            {
                if (item.NodeType == XmlNodeType.Element)
                {
                    if (list == null)
                    {
                        list = new List <IXmlNode>();
                    }
                    list.Add(item);
                }
            }
            if (list != null)
            {
                list.Reverse();
                using (List <IXmlNode> .Enumerator enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        manager.PushScope();
                        foreach (IXmlNode node3 in enumerator.Current.Attributes)
                        {
                            if ((node3.NamespaceUri == "http://www.w3.org/2000/xmlns/") && (node3.LocalName != "xmlns"))
                            {
                                manager.AddNamespace(node3.LocalName, node3.Value);
                            }
                        }
                    }
                }
            }
        }
Example #12
0
        private static void SerializeElement(XmlWriter writer, XmlNamespaceManager manager, Element element)
        {
            if (WriteStartTag(writer, manager, element, out string ns))
            {
                manager.PushScope();
                WriteAttributes(writer, manager, element);

                // Add the default namespace (if there is one) here so that it
                // takes precedence over other prefixes with the same namespace
                if (ns != null)
                {
                    manager.AddNamespace(string.Empty, ns);
                }

                WriteData(writer, element.InnerText);

                // Write the child elements: serialized, children then unknown children.
                WriteElements(writer, manager, element);
                SerializeElements(writer, manager, element.Children);
                SerializeElements(writer, manager, element.Orphans);

                writer.WriteEndElement();
                manager.PopScope();
            }
        }
        /// <summary>Pushes the specifed <paramref name="element" /> namespaces and those of ancestors.</summary>
        /// <param name="element">Element to push.</param>
        /// <param name="xsiType">The value for xsi:type on this element.</param>
        /// <param name="xsiNil">The value for xsi:nil on this element.</param>
        private void PushElement(XElement element, ref string xsiType, ref string xsiNil)
        {
            Debug.Assert(element != null, "e != null");
            namespaceManager.PushScope();
            foreach (XAttribute attribute in element.Attributes())
            {
                if (attribute.IsNamespaceDeclaration)
                {
                    string localName = attribute.Name.LocalName;
                    if (localName == "xmlns")
                    {
                        localName = string.Empty;
                    }

                    namespaceManager.AddNamespace(localName, attribute.Value);
                }
                else
                {
                    XName name = attribute.Name;
                    if (name == xsiTypeName)
                    {
                        xsiType = attribute.Value;
                    }
                    else if (name == xsiNilName)
                    {
                        xsiNil = attribute.Value;
                    }
                }
            }
        }
        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);
            }
        }
Example #15
0
        private void PushParentNamespaces(IXmlNode node, XmlNamespaceManager manager)
        {
            List <IXmlNode> list     = (List <IXmlNode>)null;
            IXmlNode        xmlNode1 = node;

            while ((xmlNode1 = xmlNode1.ParentNode) != null)
            {
                if (xmlNode1.NodeType == XmlNodeType.Element)
                {
                    if (list == null)
                    {
                        list = new List <IXmlNode>();
                    }
                    list.Add(xmlNode1);
                }
            }
            if (list == null)
            {
                return;
            }
            list.Reverse();
            foreach (IXmlNode xmlNode2 in list)
            {
                manager.PushScope();
                foreach (IXmlNode xmlNode3 in (IEnumerable <IXmlNode>)xmlNode2.Attributes)
                {
                    if (xmlNode3.NamespaceUri == "http://www.w3.org/2000/xmlns/" && xmlNode3.LocalName != "xmlns")
                    {
                        manager.AddNamespace(xmlNode3.LocalName, xmlNode3.Value);
                    }
                }
            }
        }
        private void method_1(Interface10 interface10_0, XmlNamespaceManager xmlNamespaceManager_0)
        {
            List <Interface10> list = null;
            Interface10        item = interface10_0;

            while ((item = item.Interface10_0) != null)
            {
                if (item.XmlNodeType_0 == XmlNodeType.Element)
                {
                    if (list == null)
                    {
                        list = new List <Interface10>();
                    }
                    list.Add(item);
                }
            }
            if (list != null)
            {
                list.Reverse();
                foreach (Interface10 interface3 in list)
                {
                    xmlNamespaceManager_0.PushScope();
                    foreach (Interface10 interface4 in interface3.Prop_1)
                    {
                        if ((interface4.String_2 == "http://www.w3.org/2000/xmlns/") && (interface4.String_0 != "xmlns"))
                        {
                            xmlNamespaceManager_0.AddNamespace(interface4.String_0, interface4.String_1);
                        }
                    }
                }
            }
        }
        private void PushParentNamespaces(IXmlNode node, XmlNamespaceManager manager)
        {
            List <IXmlNode> list    = null;
            IXmlNode        xmlNode = node;

            while ((xmlNode = xmlNode.ParentNode) != null)
            {
                if (xmlNode.NodeType == XmlNodeType.Element)
                {
                    if (list == null)
                    {
                        list = new List <IXmlNode>();
                    }
                    list.Add(xmlNode);
                }
            }
            if (list != null)
            {
                list.Reverse();
                foreach (IXmlNode current in list)
                {
                    manager.PushScope();
                    foreach (IXmlNode current2 in current.Attributes)
                    {
                        if (current2.NamespaceUri == "http://www.w3.org/2000/xmlns/" && current2.LocalName != "xmlns")
                        {
                            manager.AddNamespace(current2.LocalName, current2.Value);
                        }
                    }
                }
            }
        }
        void PushElement(XElement e, ref string xsiType, ref string xsiNil)
        {
            namespaceManager.PushScope();
            XAttribute a = e.lastAttr;

            if (a != null)
            {
                do
                {
                    a = a.next;
                    if (a.IsNamespaceDeclaration)
                    {
                        string localName = a.Name.LocalName;
                        if (localName == "xmlns")
                        {
                            localName = string.Empty;
                        }
                        namespaceManager.AddNamespace(localName, a.Value);
                    }
                    else
                    {
                        XName name = a.Name;
                        if (name == xsiTypeName)
                        {
                            xsiType = a.Value;
                        }
                        else if (name == xsiNilName)
                        {
                            xsiNil = a.Value;
                        }
                    }
                } while (a != e.lastAttr);
            }
        }
Example #19
0
        // Token: 0x0600102B RID: 4139 RVA: 0x00050AF8 File Offset: 0x0004ECF8
        private void tmethod_2962(Class_387 arg_0, XmlNamespaceManager arg_1)
        {
            List <Class_387> list   = null;
            Class_387        class_ = arg_0;

            while ((class_ = class_.prop_4) != null)
            {
                if (class_.prop_0 == XmlNodeType.Element)
                {
                    if (list == null)
                    {
                        list = new List <Class_387>();
                    }
                    list.Add(class_);
                }
            }
            if (list != null)
            {
                list.Reverse();
                foreach (Class_387 class_2 in list)
                {
                    arg_1.PushScope();
                    foreach (Class_387 class_3 in class_2.prop_3)
                    {
                        if (class_3.prop_6 == "http://www.w3.org/2000/xmlns/" && class_3.prop_1 != "xmlns")
                        {
                            arg_1.AddNamespace(class_3.prop_1, class_3.prop_5);
                        }
                    }
                }
            }
        }
Example #20
0
        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);
            }
        }
Example #21
0
        private static XmlNodeList GetNamedNodes(XmlDocument document, string name)
        {
            var xnsMgr = new XmlNamespaceManager(document.NameTable);

            xnsMgr.AddNamespace("z", ZuoraNamespaces.Request);
            xnsMgr.PushScope();
            return(document.SelectNodes(string.Format("//z:{0}[count(*)>0]", name), xnsMgr));
        }
Example #22
0
    // Check the "PopScope" method.
    public void TestXmlNamespaceManagerPopScope()
    {
        NameTable           table = new NameTable();
        XmlNamespaceManager ns    = new XmlNamespaceManager(table);

        Assert("PopScope (1)", !ns.PopScope());
        ns.PushScope();
        Assert("PopScope (2)", ns.PopScope());
    }
Example #23
0
    // 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"));
    }
Example #24
0
        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 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 = ReadAttributeElements(reader, manager);
            string      prefix     = MiscellaneousUtils.GetPrefix(propertyName);
            IXmlElement xmlElement = CreateElement(propertyName, document, prefix, manager);

            currentNode.AppendChild(xmlElement);
            foreach (KeyValuePair <string, string> item in dictionary)
            {
                string prefix2 = MiscellaneousUtils.GetPrefix(item.Key);
                object xmlNode2;
                if (!string.IsNullOrEmpty(prefix2))
                {
                    IXmlNode xmlNode = document.CreateAttribute(item.Key, manager.LookupNamespace(prefix2), item.Value);
                    xmlNode2 = xmlNode;
                }
                else
                {
                    xmlNode2 = document.CreateAttribute(item.Key, item.Value);
                }
                IXmlNode attributeNode = (IXmlNode)xmlNode2;
                xmlElement.SetAttributeNode(attributeNode);
            }
            if (reader.TokenType == JsonToken.String)
            {
                xmlElement.AppendChild(document.CreateTextNode(reader.Value.ToString()));
            }
            else if (reader.TokenType == JsonToken.Integer)
            {
                xmlElement.AppendChild(document.CreateTextNode(XmlConvert.ToString((long)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Float)
            {
                xmlElement.AppendChild(document.CreateTextNode(XmlConvert.ToString((double)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Boolean)
            {
                xmlElement.AppendChild(document.CreateTextNode(XmlConvert.ToString((bool)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Date)
            {
                DateTime value = (DateTime)reader.Value;
                xmlElement.AppendChild(document.CreateTextNode(XmlConvert.ToString(value, DateTimeUtils.ToSerializationMode(value.Kind))));
            }
            else if (reader.TokenType != JsonToken.Null && reader.TokenType != JsonToken.EndObject)
            {
                manager.PushScope();
                DeserializeNode(reader, document, manager, xmlElement);
                manager.PopScope();
            }
        }
        private void ProcessAppInfoDocMarkup(bool root)
        {
            //First time reader is positioned on AppInfo or Documentation element
            XmlNode currentNode = null;

            switch (reader.NodeType)
            {
            case XmlNodeType.Element:
                annotationNSManager.PushScope();
                currentNode = LoadElementNode(root);
                break;

            case XmlNodeType.Text:
                currentNode = dummyDocument.CreateTextNode(reader.Value);
                goto default;

            case XmlNodeType.SignificantWhitespace:
                currentNode = dummyDocument.CreateSignificantWhitespace(reader.Value);
                goto default;

            case XmlNodeType.CDATA:
                currentNode = dummyDocument.CreateCDataSection(reader.Value);
                goto default;

            case XmlNodeType.EntityReference:
                currentNode = dummyDocument.CreateEntityReference(reader.Name);
                goto default;

            case XmlNodeType.Comment:
                currentNode = dummyDocument.CreateComment(reader.Value);
                goto default;

            case XmlNodeType.ProcessingInstruction:
                currentNode = dummyDocument.CreateProcessingInstruction(reader.Name, reader.Value);
                goto default;

            case XmlNodeType.EndEntity:
                break;

            case XmlNodeType.Whitespace:
                break;

            case XmlNodeType.EndElement:
                annotationNSManager.PopScope();
                parentNode = parentNode.ParentNode;
                break;

            default:     //other possible node types: Document/DocType/DocumentFrag/Entity/Notation/Xmldecl cannot appear as children of xs:appInfo or xs:doc
                Debug.Assert(currentNode != null);
                Debug.Assert(parentNode != null);
                parentNode.AppendChild(currentNode);
                break;
            }
        }
Example #27
0
        /// <summary>
        /// Perform scan.
        /// </summary>
        public void Analyze(QilNode nd, bool defaultNmspInScope)
        {
            _addInScopeNmsp = false;
            _cntNmsp        = 0;

            // If xmlns="" is in-scope, push it onto the namespace stack
            if (defaultNmspInScope)
            {
                _nsmgr.PushScope();
                _nsmgr.AddNamespace(string.Empty, string.Empty);
                _cntNmsp++;
            }

            AnalyzeContent(nd);

            if (defaultNmspInScope)
            {
                _nsmgr.PopScope();
            }
        }
Example #28
0
 public DynamicRDLC(string filename)
 {
     ns            = "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition";
     this.filename = filename;
     doc           = new XmlDocument();
     doc.Load(filename);
     root = doc.DocumentElement;
     xnm  = new XmlNamespaceManager(doc.NameTable);
     xnm.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
     xnm.AddNamespace("default", ns);
     xnm.PushScope();
 }
Example #29
0
        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 = this.ReadAttributeElements(reader, manager);

            string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);

            IXmlElement element = this.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(this.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();

                    this.DeserializeNode(reader, document, manager, element);

                    manager.PopScope();
                }
            }
        }
Example #30
0
        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;
            }
        }
	// Test enumerating over a namespace manager.
	public void TestXmlNamespaceManagerEnumerate()
			{
				NameTable table = new NameTable();
				XmlNamespaceManager ns = new XmlNamespaceManager(table);
				ns.AddNamespace("foo", "uri1");
				CheckEnum(ns, "uri1");
				ns.PushScope();
				ns.AddNamespace("foo", "uri2");
				CheckEnum(ns, "uri2");
				ns.AddNamespace("foo", "uri3");
				CheckEnum(ns, "uri3");
				ns.PopScope();
				ns.AddNamespace("", "");
				CheckEnum(ns, "uri1");
			}
	// 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));
			}
	// Check the "PopScope" method.
	public void TestXmlNamespaceManagerPopScope()
			{
				NameTable table = new NameTable();
				XmlNamespaceManager ns = new XmlNamespaceManager(table);
				Assert("PopScope (1)", !ns.PopScope());
				ns.PushScope();
				Assert("PopScope (2)", ns.PopScope());
			}
	// 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"));
			}