Example #1
0
 public void MoveToAttributeSimpleDummyRoot()
 {
     reader = CreateReader("1234");
     Assert.IsFalse(reader.MoveToFirstAttribute(), "#1");
     reader.Read();              // element
     Assert.IsTrue(reader.MoveToFirstAttribute(), "#2");
     Assert.AreEqual("type", reader.LocalName, "#3");
     Assert.AreEqual("number", reader.Value, "#4");
     Assert.IsTrue(reader.ReadAttributeValue(), "#5");
     Assert.AreEqual("number", reader.Value, "#6");
     Assert.IsFalse(reader.MoveToNextAttribute(), "#7");
     Assert.IsTrue(reader.MoveToFirstAttribute(), "#8");
     Assert.IsFalse(reader.MoveToNextAttribute(), "#9");
 }
Example #2
0
 public void MoveToAttributeArray()
 {
     reader = CreateReader("[]");
     Assert.IsFalse(reader.MoveToFirstAttribute(), "#1");
     reader.Read();              // element
     Assert.IsTrue(reader.MoveToFirstAttribute(), "#2");
     Assert.AreEqual("type", reader.LocalName, "#3");
     Assert.AreEqual("array", reader.Value, "#4");
     Assert.IsTrue(reader.ReadAttributeValue(), "#5");
     Assert.AreEqual("array", reader.Value, "#6");
     Assert.IsFalse(reader.MoveToNextAttribute(), "#7");
     Assert.IsTrue(reader.MoveToFirstAttribute(), "#8");
     Assert.IsFalse(reader.MoveToNextAttribute(), "#9");
 }
 public static  XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders)
 {
     if (reader.AttributeCount == 0)
     {
         return(emptyArray);
     }
     XmlAttributeHolder[] holderArray = new XmlAttributeHolder[reader.AttributeCount];
     reader.MoveToFirstAttribute();
     for (int i = 0; i < holderArray.Length; i++)
     {
         string namespaceURI = reader.NamespaceURI;
         string localName    = reader.LocalName;
         string prefix       = reader.Prefix;
         string s            = string.Empty;
         while (reader.ReadAttributeValue())
         {
             if (s.Length == 0)
             {
                 s = reader.Value;
             }
             else
             {
                 s = s + reader.Value;
             }
         }
         Deduct(prefix, ref maxSizeOfHeaders);
         Deduct(localName, ref maxSizeOfHeaders);
         Deduct(namespaceURI, ref maxSizeOfHeaders);
         Deduct(s, ref maxSizeOfHeaders);
         holderArray[i] = new XmlAttributeHolder(prefix, localName, namespaceURI, s);
         reader.MoveToNextAttribute();
     }
     reader.MoveToElement();
     return(holderArray);
 }
 public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders)
 {
     if (reader.AttributeCount == 0)
     {
         return(emptyArray);
     }
     XmlAttributeHolder[] attributes = new XmlAttributeHolder[reader.AttributeCount];
     reader.MoveToFirstAttribute();
     for (int i = 0; i < attributes.Length; i++)
     {
         string ns        = reader.NamespaceURI;
         string localName = reader.LocalName;
         string prefix    = reader.Prefix;
         string value     = string.Empty;
         while (reader.ReadAttributeValue())
         {
             if (value.Length == 0)
             {
                 value = reader.Value;
             }
             else
             {
                 value += reader.Value;
             }
         }
         Deduct(prefix, ref maxSizeOfHeaders);
         Deduct(localName, ref maxSizeOfHeaders);
         Deduct(ns, ref maxSizeOfHeaders);
         Deduct(value, ref maxSizeOfHeaders);
         attributes[i] = new XmlAttributeHolder(prefix, localName, ns, value);
         reader.MoveToNextAttribute();
     }
     reader.MoveToElement();
     return(attributes);
 }
Example #5
0
        /// <summary>Structure of a JSON document as a structure useable for lookups</summary>
        private IEnumerable <KeyValuePair <string, string> > StructureOf(XmlDictionaryReader input)
        {
            var path = new List <string>();

            do
            {
                if (XmlNodeType.Text == input.NodeType)
                {
                    yield return(new KeyValuePair <string, string>(string.Join("\\", path), input.Value));
                }
                else if (XmlNodeType.Element == input.NodeType)
                {
                    var name = input.LocalName;

                    input.MoveToFirstAttribute();
                    do
                    {
                        if ("item" == input.LocalName)
                        {
                            name = input.Value;
                        }
                    } while (input.MoveToNextAttribute());

                    input.MoveToElement();
                    path.Add(name);
                }
                else if (XmlNodeType.EndElement == input.NodeType)
                {
                    path.RemoveAt(path.Count - 1);
                }
            } while (input.Read());
        }
Example #6
0
        void ReadBodyStart()
        {
            if (body_consumed)
            {
                throw new InvalidOperationException("The message body XmlReader is already consumed.");
            }

            if (body_started)
            {
                return;
            }

            // read headers in advance.
            if (headers == null)
            {
                ReadHeaders();
            }

            // SOAP Body
            body_started = true;
            is_empty     = reader.IsEmptyElement;
            attributes   = new AttributeCollection();
            reader.MoveToContent();
            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    attributes.Add(new AttributeInfo()
                    {
                        Prefix = reader.Prefix, Name = reader.LocalName, Namespace = reader.NamespaceURI, Value = reader.Value
                    });
                } while (reader.MoveToNextAttribute());
                reader.MoveToElement();
            }
            reader.ReadStartElement("Body", Version.Envelope.Namespace);
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                is_empty = true;
                reader.Read();
            }
            else
            {
                reader.MoveToContent();
                if (reader.NodeType == XmlNodeType.Element &&
                    reader.LocalName == "Fault" &&
                    reader.NamespaceURI == Version.Envelope.Namespace)
                {
                    is_fault = true;
                }
            }
        }
Example #7
0
        public void MoveToElementSimpleDummyRoot()
        {
            reader = CreateReader("1234");
            reader.Read();              // element
            Assert.IsTrue(reader.MoveToFirstAttribute(), "#1");
            Assert.IsTrue(reader.MoveToElement(), "#1-1");

            Assert.IsTrue(reader.MoveToFirstAttribute(), "#2");
            Assert.IsTrue(reader.ReadAttributeValue(), "#2-1");
            Assert.IsTrue(reader.MoveToElement(), "#2-2");

            Assert.IsTrue(reader.MoveToFirstAttribute(), "#3");
            Assert.IsFalse(reader.MoveToNextAttribute(), "#3-1");
            Assert.IsTrue(reader.MoveToElement(), "#3-2");
        }
        private void WriteElementNode(XmlDictionaryReader reader, bool defattr)
        {
            XmlDictionaryString localName;
            XmlDictionaryString namespaceUri;

            if (reader.TryGetLocalNameAsDictionaryString(out localName) && reader.TryGetNamespaceUriAsDictionaryString(out namespaceUri))
            {
                WriteStartElement(reader.Prefix, localName, namespaceUri);
            }
            else
            {
                WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
            }
            if (defattr || !reader.IsDefault)
            {
                if (reader.MoveToFirstAttribute())
                {
                    do
                    {
                        if (reader.TryGetLocalNameAsDictionaryString(out localName) && reader.TryGetNamespaceUriAsDictionaryString(out namespaceUri))
                        {
                            WriteStartAttribute(reader.Prefix, localName, namespaceUri);
                        }
                        else
                        {
                            WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        }
                        while (reader.ReadAttributeValue())
                        {
                            if (reader.NodeType == XmlNodeType.EntityReference)
                            {
                                WriteEntityRef(reader.Name);
                            }
                            else
                            {
                                WriteTextNode(reader, true);
                            }
                        }
                        WriteEndAttribute();
                    }while (reader.MoveToNextAttribute());
                    reader.MoveToElement();
                }
            }
            if (reader.IsEmptyElement)
            {
                WriteEndElement();
            }
        }
        private static List <System.Xml.XmlNode> ReadOtherAttributes(XmlDictionaryReader reader, XmlDictionaryString ns)
        {
            int attributeCount = reader.AttributeCount;

            if (attributeCount == 0)
            {
                return(null);
            }
            XmlDocument document           = new XmlDocument();
            List <System.Xml.XmlNode> list = new List <System.Xml.XmlNode>(attributeCount);

            reader.MoveToFirstAttribute();
            do
            {
                System.Xml.XmlNode item = document.ReadNode(reader);
                if ((item == null) || (item.NamespaceURI == ns.Value))
                {
                    throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
                }
                list.Add(item);
            }while (reader.MoveToNextAttribute());
            reader.MoveToElement();
            return(list);
        }
 public override bool MoveToNextAttribute()
 {
     return(_reader.MoveToNextAttribute());
 }
Example #11
0
        void GetCompactSignatureAttributes(out string schemeUri, out string keyId, out string refs, out string sig, out string inclusivePrefixesList)
        {
            schemeUri             = String.Empty;
            keyId                 = String.Empty;
            refs                  = String.Empty;
            sig                   = String.Empty;
            inclusivePrefixesList = null;

            XmlDictionaryReader reader = this.Message.Headers.GetReaderAtHeader(this.headerIndex);

            // reader.MoveToStartElement();
            if (reader.IsEmptyElement)
            {
                throw new CompactSignatureSecurityException("Security header doesn't contain a compact signature.");
            }

            // Move on d:Sig
            reader.ReadStartElement();
            reader.MoveToStartElement();

            while (true)
            {
                if (this.IsCompactSignatureElement(reader))
                {
                    // The d:Sig element was found
                    break;
                }

                // Skip over the children of the current node,
                // because Sig must be a direct child of the Security header.
                reader.Skip();

                if (this.IsEndSecurityElement(reader))
                {
                    // The end element of Security was reached.
                    throw new CompactSignatureSecurityException("The security header doesn't contain a compact signature");
                }
            }

            bool schemeFound            = false;
            bool keyIdFound             = false;
            bool refsFound              = false;
            bool sigFound               = false;
            bool inclusivePrefixesFound = false;

            int attributeCount = reader.AttributeCount;

            if (attributeCount != 0)
            {
                reader.MoveToFirstAttribute();
                for (int i = 0; i < attributeCount; i++)
                {
                    string attribLocalName = reader.LocalName;
                    string value           = string.Empty;
                    while (reader.ReadAttributeValue())
                    {
                        if (value.Length == 0)
                        {
                            value = reader.Value;
                        }
                        else
                        {
                            value += reader.Value;
                        }
                    }

                    if (!schemeFound && String.Compare(attribLocalName, ProtocolStrings.CompactSignatureSchemeAttribute, true) == 0)
                    {
                        // Scheme
                        schemeUri   = value;
                        schemeFound = true;
                    }
                    else if (!keyIdFound && String.Compare(attribLocalName, ProtocolStrings.CompactSignatureKeyIdAttribute, true) == 0)
                    {
                        // KeyId
                        keyId      = value;
                        keyIdFound = true;
                    }
                    else if (!refsFound && String.Compare(attribLocalName, ProtocolStrings.CompactSignatureRefsAttribute, true) == 0)
                    {
                        // Refs
                        refs      = value;
                        refsFound = true;
                    }
                    else if (!sigFound && String.Compare(attribLocalName, ProtocolStrings.CompactSignatureElementName, true) == 0)
                    {
                        // Sig
                        sig      = value;
                        sigFound = true;
                    }
                    else if (!inclusivePrefixesFound && String.Compare(attribLocalName, ProtocolStrings.PrefixListAttribute, true) == 0)
                    {
                        // PrefixList
                        inclusivePrefixesList  = value;
                        inclusivePrefixesFound = true;
                    }

                    reader.MoveToNextAttribute();
                }
            }

            reader.Close();
        }