Ejemplo n.º 1
0
        private bool ParseStartTag(XmlDocument owner, XmlElement parent, XmlElement e)
        {
            e.SourceContext   = this.scanner.CurrentSourceContext;
            e.startTagContext = this.scanner.CurrentSourceContext;
            int num1 = (int)this.GetNextToken();

            if (parent == null)
            {
                owner.AddChild((Node)e);
            }
            else
            {
                parent.AddChild((Node)e);
            }
            if (this.currentToken == Token.EndOfFile)
            {
                return(true);
            }
            if (this.currentToken != Token.Identifier)
            {
                string name = "";
                if (this.currentToken == Token.StringLiteral || this.currentToken == Token.Whitespace || this.currentToken == Token.LiteralContentString)
                {
                    name = this.scanner.GetString().Replace("\n", "").Replace("\r", "");
                }
                e.Name = Identifier.For(name);
                e.Name.SourceContext = e.startTagContext;
            }
            else
            {
                e.Name = this.ParseQualifiedName();
                this.ParseAttributes(e);
                e.startTagContext.EndCol = this.scanner.CurrentSourceContext.EndCol;
                if (this.currentToken == Token.EndOfSimpleTag)
                {
                    e.SourceContext.EndCol = this.scanner.CurrentSourceContext.EndCol;
                    int num2 = (int)this.GetNextToken();
                    return(true);
                }
                if (this.currentToken == Token.EndOfTag)
                {
                    if (this.scanner.GetString() == "?>")
                    {
                        this.errorHandler.HandleError((Node)this.scanner.GetStringLiteral(), SR.ExpectingToken, ">");
                    }
                    int num2 = (int)this.GetNextToken();
                    return(false);
                }
            }
            if (this.currentToken == Token.EndOfFile)
            {
                this.errorHandler.HandleError((Node)e.Name, SR.TagNotClosed, e.Name != null ? e.Name.ToString() : "");
            }
            e.SourceContext.EndCol = this.scanner.CurrentSourceContext.EndCol;
            return(true);
        }
Ejemplo n.º 2
0
        public void AddChildTest3(string elementString, string encoding, bool?standAlone, string expected)
        {
            string[][]  tokens = TestUtils.SplitValues(elementString, '|', '¦', "!!");
            XmlDocument doc    = new XmlDocument(10, encoding, standAlone);

            foreach (string[] token in tokens)
            {
                doc.AddChild(token[0], token[1], true, token[2], true);
            }
            Assert.That(doc.GetXmlString(), Is.EqualTo(expected));
        }
Ejemplo n.º 3
0
        private XmlDocument GetSampleDocument(out string stringResult)
        {
            XmlDocument doc     = new XmlDocument();
            XmlElement  element = new XmlElement("test");

            element.AddAttribute("testAttribute", "attributeValue");
            element.SetContent("testContent");
            doc.AddChild(element);
            stringResult = doc.GetXmlString();
            return(doc);
        }
Ejemplo n.º 4
0
        /****************************************************************************
        * If json is posted to a web form then the HttpRequest.Form collection keys
        *   looks like this:
        *
        *      StoreNumber
        *      StoreName
        *      Vehicles[0].Make
        *      Vehicles[1].Make
        *      Equipment[TireStation]
        *      Equipment[Lift]
        *
        *   When the posted JSON is this:
        *
        *      {
        *          StoreNumber: 1000,
        *          StoreName:   MidTown
        *          Vehicles:
        *          [
        *            {
        *              Make: "Chevy"
        *            },
        *            {
        *              Make: "Pontiac"
        *            }
        *          ],
        *          Equipment:
        *          {
        *            TireStation: true,
        *            Lift: true,
        *          }
        *      }
        *
        ****************************************************************************/
        public static XmlDocument ToXml(this NameValueCollection collection)
        {
            XmlDocument xmlResult = new XmlDocument();
            XmlNode     xmlRoot   = xmlResult.AddChild("Data");

            foreach (string key in collection.AllKeys)
            {
                string     value  = collection[key].Trim();
                StringList parts  = new StringList(key, "[", false);
                XmlNode    xmlNew = GetFormNode(parts, 0, xmlRoot);

                xmlNew.InnerText = value;
            }

            return(xmlResult);
        }
Ejemplo n.º 5
0
        private double MXGapproach(int elementCounter, int attributeCounter, string elementNameTemplate, string attributeNameTemplate, string attributeValueTemplate)
        {
            DateTime    now  = DateTime.Now;
            XmlDocument doc  = new XmlDocument(elementCounter);
            XmlElement  root = doc.AddChild("root");

            for (int i = 0; i < elementCounter; i++)
            {
                XmlElement element = new XmlElement(elementNameTemplate, null, null, 0, attributeCounter);
                for (int j = 0; j < attributeCounter; j++)
                {
                    element.AddAttribute(attributeNameTemplate + j, attributeValueTemplate, true, false);
                }
                root.AddChild(element);
            }
            String   output = doc.GetXmlString();
            TimeSpan t      = DateTime.Now - now;

            return(t.TotalMilliseconds);
        }
Ejemplo n.º 6
0
        private static double MXGapproach(int numberOfElements, int numerOfAttributes, List <string> elemetNames, List <string> attributeNames, List <string> attributeValues)
        {
            DateTime    now  = DateTime.Now;
            XmlDocument doc  = new XmlDocument(numberOfElements);
            XmlElement  root = doc.AddChild("root");

            for (int i = 0; i < numberOfElements; i++)
            {
                XmlElement element = new XmlElement(elemetNames[i], null, null, 0, numerOfAttributes);
                for (int j = 0; j < numerOfAttributes; j++)
                {
                    element.AddAttribute(attributeNames[j], attributeValues[j], true, false);
                    // element.AddAttribute(attributeNameTemplate + j, attributeValueTemplate, true, false);
                }
                root.AddChild(element);
            }
            String   output = doc.GetXmlString();
            TimeSpan t      = DateTime.Now - now;

            return(t.TotalMilliseconds);
        }
Ejemplo n.º 7
0
        public virtual XmlDocument ParseDocument()
        {
            int         num1        = (int)this.GetNextToken();
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Location      = this.doc.Name;
            this.root                 = xmlDocument;
            xmlDocument.SourceContext = new SourceContext(this.doc, 0, this.doc.Text.Length);
            while (this.currentToken != Token.EndOfFile)
            {
                switch (this.currentToken)
                {
                case Token.StartOfTag:
                    this.ParseElement(xmlDocument, (XmlElement)null);
                    continue;

                case Token.StartLiteralComment:
                    this.ParseComment((XmlNode)xmlDocument);
                    continue;

                case Token.LiteralContentString:
                    Literal stringLiteral = this.scanner.GetStringLiteral();
                    if (!(stringLiteral.Value.ToString() == ""))
                    {
                        if (stringLiteral is WhitespaceLiteral)
                        {
                            xmlDocument.AddChild((Node)stringLiteral);
                        }
                        else
                        {
                            this.errorHandler.HandleError((Node)stringLiteral, SR.UnexpectedToken, this.scanner.GetString());
                        }
                    }
                    int num2 = (int)this.GetNextToken();
                    continue;

                case Token.MarkupDeclaration:
                    this.ParseXmlMarkupDeclaration(xmlDocument);
                    continue;

                case Token.StartCharacterData:
                    this.ParseCData((XmlNode)xmlDocument);
                    continue;

                case Token.StartProcessingInstruction:
                    this.ParseProcessingInstruction((XmlNode)xmlDocument);
                    continue;

                default:
                    this.errorHandler.HandleError((Node)this.scanner.GetStringLiteral(), SR.UnexpectedToken, this.scanner.GetString());
                    int num3 = (int)this.GetNextToken();
                    continue;
                }
            }
            for (Node node = xmlDocument.FirstChild; node != null; node = node.NextNode)
            {
                XmlDeclaration xmlDeclaration = node as XmlDeclaration;
                if (xmlDeclaration != null)
                {
                    xmlDocument.XmlDecl = xmlDeclaration;
                }
            }
            return(xmlDocument);
        }