private IEnumerable <TypedElementOnSourceNode> enumerateElements(Dictionary <string, IElementDefinitionSummary> dis, ISourceNode parent, string name)
        {
            IEnumerable <ISourceNode> childSet;

            // no name filter: work on all the parent's children
            if (name == null)
            {
                childSet = parent.Children();
            }
            else
            {
                var hit = tryGetBySuffixedName(dis, name, out var info);
                childSet = hit && info.IsChoiceElement ?
                           parent.Children(name + "*") :
                           parent.Children(name);
            }

            string lastName   = null;
            int    _nameIndex = 0;

            foreach (var scan in childSet)
            {
                var    hit          = tryGetBySuffixedName(dis, scan.Name, out var info);
                string instanceType = info == null ? null :
                                      deriveInstanceType(scan, info);

                // If we have definitions for the children, but we didn't find definitions for this
                // child in the instance, complain
                if (dis.Any() && info == null)
                {
                    raiseTypeError($"Encountered unknown element '{scan.Name}' at location '{scan.Location}' while parsing", this,
                                   warning: _settings.ErrorMode != TypedElementSettings.TypeErrorMode.Report);

                    // don't include member, unless we are explicitly told to let it pass
                    if (_settings.ErrorMode != TypedElementSettings.TypeErrorMode.Passthrough)
                    {
                        continue;
                    }
                }

                if (lastName == scan.Name)
                {
                    _nameIndex += 1;
                }
                else
                {
                    _nameIndex = 0;
                    lastName   = scan.Name;
                }

                var prettyPath =
                    hit && !info.IsCollection ? $"{ShortPath}.{info.ElementName}" : $"{ShortPath}.{scan.Name}[{_nameIndex}]";

                // Special condition for ccda.
                // If we encounter a xhtml node in a ccda document we will flatten all childnodes
                // and use their content to build up the xml.
                // The xml will be put in this node and children will be ignored.
                if (instanceType == XHTML_INSTANCETYPE && info.Representation == XmlRepresentation.CdaText)
                {
#pragma warning disable CS0618 // Type or member is obsolete
                    var xmls = scan.Children().Select(c => c.Annotation <ICdaInfoSupplier>()?.XHtmlText);
#pragma warning restore CS0618 // Type or member is obsolete

                    var source = SourceNode.Valued(scan.Name, string.Join(string.Empty, xmls));
                    yield return(new TypedElementOnSourceNode(this, source, info, instanceType, prettyPath));

                    continue;
                }

                yield return(new TypedElementOnSourceNode(this, scan, info, instanceType, prettyPath));
            }
        }
Exemple #2
0
 public int IndexOf(SourceNode item) => _wrapped.IndexOf(item);
Exemple #3
0
 public void Add(SourceNode child)
 {
     AddRange(new[] { child });
 }
Exemple #4
0
 public bool Contains(SourceNode item) => _wrapped.Contains(item);