Esempio n. 1
0
        public static void BuildXml()
        {
            XmlNode            rootNode = doc.CreateElement("Recipe");
            var                allText  = File.ReadAllText(@"C:\Users\abrhm\source\repos\RecipeReader\RecipeReader\1_LemonCake.txt");
            NodeRepresentation header   = new NodeRepresentation("Header", @"\d\.", null, ReadingRule.HEADER);

            NodeRepresentation[] ingredients = { new NodeRepresentation("Ingredient", @"\n", null) };
            NodeRepresentation[] steps       = { new NodeRepresentation("Step", @"\d\.", null) };

            NodeRepresentation[] categories = { header, new NodeRepresentation("Ingredients", "Ingredients:", ingredients), new NodeRepresentation("Method", "Method:", steps) };
            BuildNode(rootNode, categories, allText);
            doc.AppendChild(rootNode);
            doc.Save(@"C:\Users\abrhm\source\repos\RecipeReader\RecipeReader\EncodedRecipe.xml");
        }
Esempio n. 2
0
        private static void BuildShallowNode(string nodeText, NodeRepresentation shallowNodeRepresentation, XmlNode parentNode)
        {
            var words = Regex.Split(nodeText, shallowNodeRepresentation.StartSeparator);

            foreach (var word in words)
            {
                XmlNode shallowNode = doc.CreateElement(shallowNodeRepresentation.XmlName);
                if (string.IsNullOrWhiteSpace(word))
                {
                    continue;
                }
                shallowNode.InnerText = word.Trim();
                parentNode.AppendChild(shallowNode);
            }
        }
Esempio n. 3
0
        private static void BuildHeaderNode(string text, NodeRepresentation nodeRep, XmlNode parentNode)
        {
            var pattern = @"(\d)\.(.+)\[(.+)\].+";

            var match        = Regex.Match(text, pattern);
            var recipeNumber = match.Groups[1].Value;
            var recipeTitle  = match.Groups[2].Value.Trim();
            var datePosted   = match.Groups[3].Value;

            XmlNode newNode    = doc.CreateElement(nodeRep.XmlName);
            XmlNode numberNode = doc.CreateElement("RecipeNumber");

            numberNode.InnerText = recipeNumber;
            XmlNode titleNode = doc.CreateElement("Title");

            titleNode.InnerText = recipeTitle;
            XmlNode dateNode = doc.CreateElement("Date");

            dateNode.InnerText = datePosted;
            newNode.AppendChild(numberNode);
            newNode.AppendChild(titleNode);
            newNode.AppendChild(dateNode);
            parentNode.AppendChild(newNode);
        }