Ejemplo n.º 1
0
        public void CopyTo()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<root a1='garnet' a2='amethyst' a3='Bloodstone' a4='diamond' a5='emerald' a6='pearl' a7='ruby' a8='sapphire' a9='moonstone' a10='opal' a11='topaz' a12='turquoize' />");
            XmlAttributeCollection col = xmlDoc.DocumentElement.Attributes;

            XmlAttribute[] array = new XmlAttribute[24];
            col.CopyTo(array, 0);
            Assert.AreEqual("garnet", array[0].Value);
            Assert.AreEqual("moonstone", array[8].Value);
            Assert.AreEqual("turquoize", array[11].Value);
            col.CopyTo(array, 12);
            Assert.AreEqual("garnet", array[12].Value);
            Assert.AreEqual("moonstone", array[20].Value);
            Assert.AreEqual("turquoize", array[23].Value);
        }
Ejemplo n.º 2
0
        public async Task PostRequestAsync()
        {
            WebRequest request = WebRequest.Create("https://sandbox.payture.com/api/Pay");

            request.Method = "POST"; // для отправки используется метод Post
                                     // данные для отправки
            string data = this.ToString();

            // преобразуем данные в массив байтов
            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(data);
            // устанавливаем тип содержимого - параметр ContentType
            request.ContentType = "application/x-www-form-urlencoded";
            // Устанавливаем заголовок Content-Length запроса - свойство ContentLength
            request.ContentLength = byteArray.Length;

            //записываем данные в поток запроса
            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }
            XmlDocument xml;
            WebResponse response = await request.GetResponseAsync();

            using (Stream stream = response.GetResponseStream())
            {
                xml = new XmlDocument();
                xml.Load(stream);
            }
            response.Close();
            XmlElement             xroot = xml.DocumentElement;
            XmlAttributeCollection att   = xroot.Attributes;

            XmlAttribute[] art = new XmlAttribute[att.Count];
            att.CopyTo(art, 0);
            Dictionary <string, string> attributes = new Dictionary <string, string>();

            foreach (var item in art)
            {
                attributes.Add(item.Name, item.InnerText);
            }
            Response resp = new Response()
            {
                Method  = xroot.Name,
                OrderId = attributes["OrderId"],
                Key     = attributes["Key"],
                Success = attributes["Success"],
                ErrCode = attributes["ErrCode"],
            };

            Console.WriteLine(resp.ToString());
        }
Ejemplo n.º 3
0
        public void CopyToCopiesClonedAttributesAtSpecifiedLocation()
        {
            XmlDocument  doc = CreateDocumentWithElement();
            XmlElement   element = doc.DocumentElement;
            XmlAttribute attr1, attr2;

            attr1 = element.Attributes.Append(doc.CreateAttribute("attr1"));
            attr2 = element.Attributes.Append(doc.CreateAttribute("attr2"));
            XmlAttribute[] destinationArray = new XmlAttribute[4];

            XmlAttributeCollection target = element.Attributes;

            target.CopyTo(destinationArray, 2);

            Assert.Null(destinationArray[0]);
            Assert.Null(destinationArray[1]);
            Assert.NotNull(destinationArray[2]);
            Assert.NotNull(destinationArray[3]);
        }
Ejemplo n.º 4
0
        public void CopyToCopiesClonedAttributes()
        {
            XmlDocument  doc = CreateDocumentWithElement();
            XmlElement   element = doc.DocumentElement;
            XmlAttribute attr1, attr2;

            attr1 = element.Attributes.Append(doc.CreateAttribute("attr1"));
            attr2 = element.Attributes.Append(doc.CreateAttribute("attr2"));
            XmlAttribute[] destinationArray = new XmlAttribute[2];

            XmlAttributeCollection target = element.Attributes;

            target.CopyTo(destinationArray, 0);

            Assert.NotNull(destinationArray[0]);
            Assert.NotSame(attr1, destinationArray[0]);
            Assert.NotSame(element, destinationArray[0].OwnerElement);
            Assert.Equal("attr1", destinationArray[0].LocalName);
            Assert.NotNull(destinationArray[1]);
            Assert.NotSame(attr2, destinationArray[1]);
            Assert.NotSame(element, destinationArray[1].OwnerElement);
            Assert.Equal("attr2", destinationArray[1].LocalName);
        }
Ejemplo n.º 5
0
    public static void Main()
    {
        XmlDocument doc = new XmlDocument();

        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                    "<title>Pride And Prejudice</title>" +
                    "</book>");

        //Create an attribute collection.
        XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;

        //Declare the array.
        XmlAttribute[] array = new XmlAttribute[2];
        int            index = 0;

        //Copy all the attributes into the array.
        attrColl.CopyTo(array, index);

        Console.WriteLine("Display all the attributes in the array..");
        foreach (XmlAttribute attr in array)
        {
            Console.WriteLine("{0} = {1}", attr.Name, attr.Value);
        }
    }