Example #1
0
        public void FillDocument(XmlDocument doc, SudokuGrid grid, int CM)
        {
            XmlNode rows1   = doc.CreateNode(XmlNodeType.Element, "Rows", "");
            XmlNode rows2   = doc.CreateNode(XmlNodeType.Element, "Rows", "");
            XmlNode sudoku  = doc.CreateNode(XmlNodeType.Element, "Sudoku", "");
            XmlNode hints   = doc.CreateNode(XmlNodeType.Element, "Hints", "");
            XmlNode guesses = doc.CreateNode(XmlNodeType.Element, "Guesses", "");

            doc.AppendChild(sudoku);
            sudoku.AppendChild(hints);
            sudoku.AppendChild(guesses);
            guesses.AppendChild(rows1);
            hints.AppendChild(rows2);

            for (int row = 0; row < 10; row++)
            {
                XmlNode node  = doc.CreateNode(XmlNodeType.Element, "Row", "");
                XmlNode node2 = doc.CreateNode(XmlNodeType.Element, "Row", "");
                rows1.AppendChild(node2);
                rows2.AppendChild(node);
                if (row == 9)
                {
                    node2.InnerText += CM.ToString();
                }
                else
                {
                    for (int col = 0; col < 9; col++)
                    {
                        if (grid[row, col] == 0)
                        {
                            node.InnerText  += "-,";
                            node2.InnerText += "-,";
                        }
                        else
                        {
                            if (grid.IsKnownElement(row, col))
                            {
                                node.InnerText  += grid[row, col] + ",";
                                node2.InnerText += "-,";
                            }
                            else
                            {
                                node.InnerText  += "-,";
                                node2.InnerText += grid[row, col] + ",";
                            }
                        }
                    }

                    if (node.InnerText.Length > 0)
                    {
                        node.InnerText = node.InnerText.Remove(node.InnerText.Length - 1, 1);
                    }

                    if (node2.InnerText.Length > 0)
                    {
                        node2.InnerText = node2.InnerText.Remove(node2.InnerText.Length - 1, 1);
                    }
                }
            }
        }