示例#1
0
        public Day04()
        {
            foreach (var line in InputFile.Split("\r\n\r\n"))
            {
                var doc = new Document();

                foreach (var attr in line.Replace("\r\n", " ").Split(" "))
                {
                    var pos = attr.IndexOf(":");
                    doc.AddAttribute(attr.Substring(0, pos), attr[(pos + 1)..]);
示例#2
0
        public Document Parse()
        {
            Document document = new Document();

            if (Read() != '<')
            {
                throw new FormatException();
            }
            if (Peek() == '?')
            {
                Read();
                string name = ReadString(); // xml
                SkipWhiteSpace();
                while (Peek() != '?')
                {
                    Attribute attr = ReadAttribute();
                    if (attr.Name.IsString)
                    {
                        if (((string)attr.Name.Value).ToLower() == "version")
                        {
                            document.Version = attr.Value;
                        }
                    }

                    document.AddAttribute(attr);
                    SkipWhiteSpace();
                }
                ReadUntil('>'); //skip xml header
                Read();
                SkipWhiteSpace();
                Read(); //skip <
                document.Add(ReadNode());
            }
            else
            {
                document.Add(ReadNode());
            }
            return(document);
        }