public override IEnumerable<Row> Execute(IEnumerable<Row> rows) {
            foreach (var row in rows) {
                if (ShouldRun(row)) {

                    var xml = row[InKey].ToString();
                    if (xml.Equals(string.Empty)) {
                        yield return row;
                        continue;
                    }

                    var count = 0;
                    var doc = new NanoXmlDocument(xml);
                    if (_elements.ContainsKey(doc.RootNode.Name)) {
                        var field = _elements[doc.RootNode.Name];
                        row[field.Alias] = _converter[field.SimpleType](doc.RootNode.Value ?? (field.ReadInnerXml ? doc.RootNode.InnerText() : doc.RootNode.ToString()));
                        count++;
                    }

                    var subNodes = doc.RootNode.SubNodes.ToArray();
                    while (subNodes.Any()) {
                        var nextNodes = new List<NanoXmlNode>();
                        foreach (var node in subNodes) {
                            if (_elements.ContainsKey(node.Name)) {
                                var field = _elements[node.Name];
                                count++;
                                var value = node.Value ?? (field.ReadInnerXml ? node.InnerText() : node.ToString());
                                if (!string.IsNullOrEmpty(value)) {
                                    row[field.Alias] = _converter[field.SimpleType](value);
                                }
                            }
                            if (_searchAttributes) {
                                foreach (var attribute in node.Attributes.Where(attribute => _attributes.ContainsKey(attribute.Name))) {
                                    var field = _attributes[attribute.Name];
                                    count++;
                                    if (!string.IsNullOrEmpty(attribute.Value)) {
                                        row[field.Alias] = _converter[field.SimpleType](attribute.Value);
                                    }
                                }
                            }
                            if (count < _total) {
                                nextNodes.AddRange(node.SubNodes);
                            }
                        }
                        subNodes = nextNodes.ToArray();
                    }
                    yield return row;
                } else {
                    Interlocked.Increment(ref SkipCount);
                    yield return row;
                }
            }
        }
示例#2
0
        public Row Transform(Row row) {
            var xml = row.GetString(_input);
            if (xml.Equals(string.Empty)) {
                return row;
            }

            var count = 0;
            var doc = new NanoXmlDocument(xml);
            if (_elements.ContainsKey(doc.RootNode.Name)) {
                var field = _elements[doc.RootNode.Name];
                row[field] = field.Convert(doc.RootNode.Value ?? (field.ReadInnerXml ? doc.RootNode.InnerText() : doc.RootNode.ToString()));
                count++;
            }

            var subNodes = doc.RootNode.SubNodes.ToArray();
            while (subNodes.Any()) {
                var nextNodes = new List<NanoXmlNode>();
                foreach (var node in subNodes) {
                    if (_elements.ContainsKey(node.Name)) {
                        var field = _elements[node.Name];
                        count++;
                        var value = node.Value ?? (field.ReadInnerXml ? node.InnerText() : node.ToString());
                        if (!string.IsNullOrEmpty(value)) {
                            if (field.Type == "string") {
                                row.SetString(field, value);
                            } else {
                                row[field] = field.Convert(value);
                            }
                        }
                    }
                    if (_searchAttributes) {
                        foreach (var attribute in node.Attributes.Where(attribute => _attributes.ContainsKey(attribute.Name))) {
                            var field = _attributes[attribute.Name];
                            count++;
                            if (!string.IsNullOrEmpty(attribute.Value)) {
                                if (field.Type == "string") {
                                    row.SetString(field, attribute.Value);
                                } else {
                                    row[field] = field.Convert(attribute.Value);
                                }
                            }
                        }
                    }
                    if (count < _total) {
                        nextNodes.AddRange(node.SubNodes);
                    }
                }
                subNodes = nextNodes.ToArray();
            }
            Increment();
            return row;
        }