public void Sample1() { const string xml = "<xml><something foo=\"bar\" /><baz>zoink</baz></xml>"; var subject = new XmlLexer(); var tokens = subject.GetTokens(xml).ToArray(); _output.WriteLine(tokens.DumpForCode()); Check.That(tokens).Contains( new Token(0, TokenTypes.Name.Tag, "<xml"), new Token(4, TokenTypes.Name.Tag, ">"), new Token(5, TokenTypes.Name.Tag, "<something"), new Token(15, TokenTypes.Text, " "), new Token(16, TokenTypes.Name.Attribute, "foo="), new Token(20, TokenTypes.Literal.String, "\"bar\""), new Token(25, TokenTypes.Text, " "), new Token(26, TokenTypes.Name.Tag, "/>"), new Token(28, TokenTypes.Name.Tag, "<baz"), new Token(32, TokenTypes.Name.Tag, ">"), new Token(33, TokenTypes.Text, "zoink"), new Token(38, TokenTypes.Error, "<"), new Token(39, TokenTypes.Text, "/baz>"), new Token(44, TokenTypes.Error, "<"), new Token(45, TokenTypes.Text, "/xml>") ); }
public void TestParse() { // ARRANGE WebClient wc = new WebClient(); //string markup = wc.DownloadString("http://www.wikipedia.org"); //string markup = wc.DownloadString("https://www.w3schools.com/xml/note.xml"); string markup = @" <Query> <Where> <And> <Gt> <FieldRef Name='Quantity' /> <Value Type='Number'>0</Value> </Gt> <Leq> <FieldRef Name='Price' /> <Value Type='Number'>2000</Value> </Leq> </And> </Where> </Query>"; // ACT // MarkupParser parser = new MarkupParser(); // parser.Parse( markup ); XmlLexer lexer = new XmlLexer(); lexer.Read(markup); //// OUTPUT //foreach ( XmlToken tok in lexer.GetTokens()) { // Trace.WriteLine( string.Format(" ['{0}',{1}]", tok.lexeme, tok.type) ); //} XmlParser parser = new XmlParser(); parser.Parse(lexer.GetTokens()); //parser.TraceTree(); // ASSERT XmlDocument actual = parser.Tree; XmlDocument expected = new XmlDocument(); expected.LoadXml(markup); Assert.AreEqual(actual.OuterXml, expected.OuterXml); }
public string OnSave(string source, byte additionalOptions) { string jsonString; Token[] tokens = XmlLexer.GetTokens(source); tokens = XmlLexer.AddArray(new List <string> { "AstronomicalObject", "UidHash" }, new List <string>() { "AstroObjects", "AstroObjectsEditors" }, tokens); XmlToJsonParser parser = new XmlToJsonParser((SerializationOptions)additionalOptions); jsonString = parser.GetJsonString(tokens); string removeString = "\"SaveInfo\": "; if (jsonString.Length > removeString.Length) { jsonString = jsonString.Substring(removeString.Length, jsonString.Length - removeString.Length); } return(jsonString); }