Пример #1
0
        private static DataTable CreateSelectDatatable(XmlSelect select)
        {
            DataTable dtResult = new DataTable();

            dtResult.Columns.Add("node", typeof(string));
            string sColumnName = "text";

            if (select.XPathNode.IsNameDefined)
            {
                sColumnName = select.XPathNode.Name;
            }
            if (select.XPathValues.Length == 0)
            {
                dtResult.Columns.Add(sColumnName, typeof(string));
            }
            int i = 0;

            foreach (XPath xPathValue in select.XPathValues)
            {
                sColumnName = xPathValue.Name;
                if (i == 0 && !xPathValue.IsNameDefined && select.XPathNode.IsNameDefined)
                {
                    sColumnName = select.XPathNode.Name;
                }
                sColumnName = zdt.GetNewColumnName(dtResult, sColumnName);
                //Type type = typeof(string);
                //if (xPathValue.TypeValue != null)
                //    type = xPathValue.TypeValue;
                //dtResult.Columns.Add(sColumnName, type);
                dtResult.Columns.Add(sColumnName);
                i++;
            }

            return(dtResult);
        }
Пример #2
0
        public static IEnumerable <XmlSelectValue> zGetValues(this XmlSelect select)
        {
            int nb = select.SourceXPathValues.Length;

            while (select.Get())
            {
                string[] values = new string[nb];
                select.Values.CopyTo(values, 0);
                yield return(new XmlSelectValue {
                    Path = select.PathCurrentNode, Values = values
                });
            }
        }
Пример #3
0
        public static DataTable zToDataTable(this XmlSelect select)
        {
            DataTable dtResult = CreateSelectDatatable(select);

            foreach (XmlSelectValue value in select.zGetValues())
            {
                DataRow row = dtResult.NewRow();
                row[0] = value.Path;
                int i = 1;
                foreach (string value2 in value.Values)
                {
                    row[i++] = value2;
                }
                dtResult.Rows.Add(row);
            }
            return(dtResult);
        }
Пример #4
0
        public static DataTable zToDataTable_v1(this XmlSelect select)
        {
            DataTable dtResult = CreateSelectDatatable(select);

            while (select.Get())
            {
                DataRow row = dtResult.NewRow();
                //row[0] = select.TranslatedPathCurrentNode;
                row[0] = select.PathCurrentNode;
                //row[1] = select.Values[0];
                //for (int i = 1; i < select.SourceXPathValues.Length; i++)
                //    row[i + 1] = select.GetValue(i);
                int i = 1;
                foreach (string value in select.Values)
                {
                    row[i++] = value;
                }
                dtResult.Rows.Add(row);
            }
            return(dtResult);
        }