Ejemplo n.º 1
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());
    }
 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"));
 }
Ejemplo n.º 3
0
        public XmlNamespaceManager LoadNamespace(XmlDocument wDoc)
        {
            XmlNamespaceManager res = new XmlNamespaceManager(wDoc.NameTable);

            res.PopScope();
            XmlElement rNode = wDoc.DocumentElement;
            string     nStr;

            foreach (XmlAttribute attr in rNode.Attributes)
            {
                nStr = attr.Name;
                if (nStr.Contains("xmlns"))
                {
                    if (nStr.Length == 5)
                    {
                        res.AddNamespace("ns", attr.Value); //!!
                    }
                    else
                    {
                        res.AddNamespace(nStr.Replace("xmlns:", ""), attr.Value);
                    }
                }
            }
            return(res);
        }
Ejemplo n.º 4
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();
                }
            }
        }
        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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 private void ProcessElement()
 {
     Push(elementName);
     if (_isProcessContents)
     {
         _nsManager.PopScope();
     }
     context.ElementDecl = ThoroughGetElementDecl();
     if (context.ElementDecl != null)
     {
         ValidateStartElement();
         ValidateEndStartElement();
         context.NeedValidateChildren = true;
         context.ElementDecl.ContentValidator.InitValidation(context);
     }
 }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
        // 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();
        }
        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);
            }
        }
        void ValidateElement(XElement e)
        {
            XmlSchemaInfo si      = addSchemaInfo ? new XmlSchemaInfo() : null;
            string        xsiType = null;
            string        xsiNil  = null;

            PushElement(e, ref xsiType, ref xsiNil);
            IXmlLineInfo original = SaveLineInfo(e);

            source = e;
            validator.ValidateElement(e.Name.LocalName, e.Name.NamespaceName, si, xsiType, xsiNil, null, null);
            ValidateAttributes(e);
            validator.ValidateEndOfAttributes(si);
            ValidateNodes(e);
            validator.ValidateEndElement(si);
            if (addSchemaInfo)
            {
                if (si.Validity == XmlSchemaValidity.Valid && si.IsDefault)
                {
                    e.Value = GetDefaultValue(si.SchemaElement);
                }
                ReplaceSchemaInfo(e, si);
            }
            RestoreLineInfo(original);
            namespaceManager.PopScope();
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Pops the context.
 /// </summary>
 /// <param name="nmgr">The NMGR.</param>
 /// <param name="node">The node.</param>
 private void PopContext(XmlNamespaceManager nmgr, XmlNode node)
 {
     if (node.NamespaceURI != String.Empty)
     {
         nmgr.PopScope();
         prefixSequence--;
     }
 }
Ejemplo n.º 14
0
 private void ShowAllNamespaces(XmlNamespaceManager nsmgr)
 {
     do
     {
         foreach (String prefix in nsmgr)
         {
             Console.WriteLine("Prefix={0}, Namespace={1}", prefix, nsmgr.LookupNamespace(prefix));
         }
     }while (nsmgr.PopScope());
 }
Ejemplo n.º 15
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();
            }
        }
Ejemplo n.º 17
0
        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;
            }
        }
Ejemplo n.º 18
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();
            }
        }
Ejemplo n.º 19
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();
                }
            }
        }
        public void NewNamespaceManager()
        {
            // make sure that you can call PopScope when there aren't any to pop.
            Assert.IsTrue(!namespaceManager.PopScope());

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

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

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

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

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

            // looking up undeclared namespaces should return null.
            Assert.IsNull(namespaceManager.LookupNamespace("foo"));
        }
Ejemplo n.º 21
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;
            }
        }
        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));
        }
Ejemplo n.º 23
0
 private void WriteEndElementInternal(bool fullEndElement)
 {
     CheckState();
     if (fullEndElement)
     {
         Emitter.WriteFullEndElement();
     }
     else
     {
         Emitter.WriteEndElement();
     }
     _state = WriteState.Content;
     //Pop namespace scope
     _nsManager.PopScope();
 }
Ejemplo n.º 24
0
    // 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");
    }
Ejemplo n.º 25
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> strs = this.ReadAttributeElements(reader, manager);
            string      prefix     = MiscellaneousUtils.GetPrefix(propertyName);
            IXmlElement xmlElement = this.CreateElement(propertyName, document, prefix, manager);

            currentNode.AppendChild(xmlElement);
            foreach (KeyValuePair <string, string> keyValuePair in strs)
            {
                string str = MiscellaneousUtils.GetPrefix(keyValuePair.Key);
                xmlElement.SetAttributeNode((string.IsNullOrEmpty(str) ? document.CreateAttribute(keyValuePair.Key, keyValuePair.Value) : document.CreateAttribute(keyValuePair.Key, manager.LookupNamespace(str), keyValuePair.Value)));
            }
            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, Newtonsoft.Json.Utilities.DateTimeUtils.ToSerializationMode(value.Kind))));
            }
            else if (reader.TokenType != JsonToken.Null)
            {
                if (reader.TokenType != JsonToken.EndObject)
                {
                    manager.PushScope();
                    this.DeserializeNode(reader, document, manager, xmlElement);
                    manager.PopScope();
                }
            }
        }
Ejemplo n.º 26
0
        // 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);
        }
Ejemplo n.º 27
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> dictionary = this.ReadAttributeElements(reader, manager);
            string prefix = MiscellaneousUtils.GetPrefix(propertyName);

            if (propertyName.StartsWith("@"))
            {
                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 || reader.TokenType == JsonToken.Date)
            {
                xmlElement.AppendChild(document.CreateTextNode(this.ConvertTokenToXmlValue(reader)));
                return;
            }
            if (reader.TokenType == JsonToken.Null)
            {
                return;
            }
            if (reader.TokenType != JsonToken.EndObject)
            {
                manager.PushScope();
                this.DeserializeNode(reader, document, manager, xmlElement);
                manager.PopScope();
            }
        }
Ejemplo n.º 28
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> dictionary = this.ReadAttributeElements(reader, manager);
            string prefix1 = MiscellaneousUtils.GetPrefix(propertyName);

            if (propertyName.StartsWith("@"))
            {
                string   str1      = propertyName.Substring(1);
                string   str2      = reader.Value.ToString();
                string   prefix2   = MiscellaneousUtils.GetPrefix(str1);
                IXmlNode attribute = !string.IsNullOrEmpty(prefix2) ? document.CreateAttribute(str1, manager.LookupNamespace(prefix2), str2) : document.CreateAttribute(str1, str2);
                ((IXmlElement)currentNode).SetAttributeNode(attribute);
            }
            else
            {
                IXmlElement element = this.CreateElement(propertyName, document, prefix1, manager);
                currentNode.AppendChild((IXmlNode)element);
                foreach (KeyValuePair <string, string> keyValuePair in dictionary)
                {
                    string   prefix2   = MiscellaneousUtils.GetPrefix(keyValuePair.Key);
                    IXmlNode attribute = !string.IsNullOrEmpty(prefix2) ? document.CreateAttribute(keyValuePair.Key, manager.LookupNamespace(prefix2), keyValuePair.Value) : document.CreateAttribute(keyValuePair.Key, keyValuePair.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 || reader.TokenType == JsonToken.EndObject)
                    {
                        return;
                    }
                    manager.PushScope();
                    this.DeserializeNode(reader, document, manager, (IXmlNode)element);
                    manager.PopScope();
                }
            }
        }
Ejemplo n.º 29
0
        private void method_8(JsonReader jsonReader_0, Interface11 interface11_0, Interface10 interface10_0, string string_8, XmlNamespaceManager xmlNamespaceManager_0)
        {
            if (string.IsNullOrEmpty(string_8))
            {
                throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");
            }
            Dictionary <string, string> dictionary = this.method_12(jsonReader_0, xmlNamespaceManager_0);
            string str = Class193.smethod_4(string_8);

            if (string_8.StartsWith("@"))
            {
                string      str2       = string_8.Substring(1);
                string      str3       = jsonReader_0.Object_0.ToString();
                string      str4       = Class193.smethod_4(str2);
                Interface10 interface2 = !string.IsNullOrEmpty(str4) ? interface11_0.imethod_11(str2, xmlNamespaceManager_0.LookupNamespace(str4), str3) : interface11_0.imethod_10(str2, str3);
                ((Interface12)interface10_0).imethod_1(interface2);
            }
            else
            {
                Interface12 interface3 = this.method_14(string_8, interface11_0, str, xmlNamespaceManager_0);
                interface10_0.imethod_0(interface3);
                foreach (KeyValuePair <string, string> pair in dictionary)
                {
                    string      str5       = Class193.smethod_4(pair.Key);
                    Interface10 interface4 = !string.IsNullOrEmpty(str5) ? interface11_0.imethod_11(pair.Key, xmlNamespaceManager_0.LookupNamespace(str5), pair.Value) : interface11_0.imethod_10(pair.Key, pair.Value);
                    interface3.imethod_1(interface4);
                }
                if ((((jsonReader_0.JsonToken_0 != JsonToken.String) && (jsonReader_0.JsonToken_0 != JsonToken.Integer)) && ((jsonReader_0.JsonToken_0 != JsonToken.Float) && (jsonReader_0.JsonToken_0 != JsonToken.Boolean))) && (jsonReader_0.JsonToken_0 != JsonToken.Date))
                {
                    if ((jsonReader_0.JsonToken_0 != JsonToken.Null) && (jsonReader_0.JsonToken_0 != JsonToken.EndObject))
                    {
                        xmlNamespaceManager_0.PushScope();
                        this.method_15(jsonReader_0, interface11_0, xmlNamespaceManager_0, interface3);
                        xmlNamespaceManager_0.PopScope();
                    }
                }
                else
                {
                    interface3.imethod_0(interface11_0.imethod_2(this.method_9(jsonReader_0)));
                }
            }
        }
Ejemplo n.º 30
0
    // 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 "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));
			}
	// 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");
			}