Exemple #1
0
        /// <summary>
        /// Processes the item headers from /*/table/configuration/* nodes.
        /// </summary>
        /// <param name="xml">Input xml.</param>
        /// <param name="output">Output stream.</param>
        /// <param name="settings">The settings for CSV processing.</param>
        private static void ProcessItemHeaders(XDocument xml, StreamWriter output, Settings settings)
        {
            if (xml.Root.Element("table").Element("configuration").Attribute("visible") != null &&
                xml.Root.Element("table").Element("configuration").Attribute("visible").Value == "false")
            {
                return;
            }

            var configNodes = xml.Root.Element("table").Element("configuration").Elements();

            int count = configNodes.Count();
            int i     = 0;

            foreach (XElement element in configNodes)
            {
                output.Write(MakoPrintCsv.EncapsulateFieldValue(element.Value, settings));

                if (i + 1 == count)
                {
                    output.Write("\r\n");
                }
                else
                {
                    output.Write(settings.FieldSeparator);
                }

                i++;
            }
        }
Exemple #2
0
        /// <summary>
        /// Generates a CSV file from the specified xml to the specified output stream.
        /// </summary>
        /// <param name="xml">Input xml.</param>
        /// <param name="output">Output stream.</param>
        public static void Generate(string xml, Stream output)
        {
            XDocument xdoc = XDocument.Parse(xml);

            Settings settings = MakoPrintCsv.LoadConfig(xdoc);

            StreamWriter writer = new StreamWriter(output, Encoding.GetEncoding(settings.Encoding));

            MakoPrintCsv.InsertAutonumberingElements(xdoc);
            MakoPrintCsv.ReplaceDecimalSeparators(xdoc, settings);

            MakoPrintCsv.ProcessItemHeaders(xdoc, writer, settings);
            MakoPrintCsv.ProcessItems(xdoc, writer, settings);

            writer.Flush();
        }
Exemple #3
0
        /// <summary>
        /// Processes the column values from /*/table/items/* nodes.
        /// </summary>
        /// <param name="xml">Input xml.</param>
        /// <param name="output">Output stream.</param>
        /// <param name="settings">The settings for CSV processing.</param>
        private static void ProcessItems(XDocument xml, StreamWriter output, Settings settings)
        {
            var items = xml.Root.Element("table").Element("items").Elements();

            foreach (XElement item in items)
            {
                bool firstNodePassed = false;

                foreach (XElement column in item.Elements())
                {
                    if (firstNodePassed)
                    {
                        output.Write(settings.FieldSeparator);
                    }

                    output.Write(MakoPrintCsv.EncapsulateFieldValue(column.Value, settings));

                    firstNodePassed = true;
                }

                output.Write("\r\n");
            }
        }