Пример #1
0
        protected override void ParseText(string str, Action<ParsedInfo> callback)
        {
            var xml = new XtansiveXElement() { Value = XElement.Parse(str), Address = FieldAddress.NewRoot() };
            var childs = xml.GetEndChilds();
            foreach (var ch in childs)
            {
                string addr = "";
                foreach (var s in ch.Address.Elements.Skip(1))
                    addr += (addr == "" ? "" : ".") + Retag(s);

                if (ch.Value != null)
                    callback(new ParsedInfo(new FieldAddress(addr), ch.Value.Value));
                if (ch.AdditionalInfo != null)
                    callback(new ParsedInfo(new FieldAddress(addr), ch.AdditionalInfo.Item2, -1, ch.AdditionalInfo.Item1));
            }
        }
Пример #2
0
        public static IEnumerable<XtansiveXElement> GetEndChilds(this XtansiveXElement current)
        {
            var els = current.Value.Elements();
               /* if (current.Value.Name.LocalName == XML.Prefix)
            {
                if (!current.Address.IsRoot)
                {
                    var item = current.Value.Attribute(XName.Get("item")).Value;
                    current.Address = current.Address.Child(item);
                }
            }
            else*/
                current.Address = current.Address.Child(current.Value.Name.LocalName);
            foreach (var info in current.Value.Attributes().Select(a => new Tuple<string, string>(a.Name.LocalName, a.Value)))
                yield return new XtansiveXElement() { Address = current.Address, AdditionalInfo = info };
            if (els.Count() == 0) yield return current;
            var upd = els.Select(a =>
            {

                var v = new XtansiveXElement() { Value = a };
                //if (current.Value.Name.LocalName == XML.Prefix)
                //    v.Address = FieldAddress.NewRoot();
                //else
                v.Address = current.Address;
                return v;
            });
            foreach (var e in upd.SelectMany(a => a.GetEndChilds()))
                yield return e;
        }