Ejemplo n.º 1
0
        public virtual FhirInstanceTree ConstructTreeNode(XObject docNode, FhirInstanceTree parent)
        {
            var  docElement  = (XElement)docNode;
            var  newNodeName = docElement.Name.LocalName;      // ignore namespace, it's always FHIRNS
            bool hasValue    = false;

#if NET40
            string value = null;
            if (docElement.HasAttributes)
            {
                var attr = docElement.Attribute(XVALUE);
                if (attr != null)
                {
                    value    = attr.Value;
                    hasValue = true;
                }
            }
#else
            string value = docElement.TryGetAttribute(XVALUE, out hasValue);
#endif
            FhirInstanceTree result = null;

            if (hasValue)
            {
                result = parent.AddLastChild(newNodeName, (IValueProvider) new UntypedValue(value));
            }
            else
            {
                result = parent.AddLastChild(newNodeName);
            }

            result.AddAnnotation(docElement);
            return(result);
        }
Ejemplo n.º 2
0
        public FhirInstanceTree ConstructTreeNode(XObject docNode, FhirInstanceTree parent)
        {
            var result             = FhirInstanceTree.Create("(root)");
            var nestedResourceName = ((XDocument)docNode).Root.Name.LocalName;

            result.AddAnnotation(new XmlRenderHints {
                NestedResourceName = nestedResourceName
            });

            return(result);
        }
        public override FhirInstanceTree ConstructTreeNode(XObject docNode, FhirInstanceTree parent)
        {
            var result             = base.ConstructTreeNode(docNode, parent);
            var nestedResourceName = ((XElement)docNode).Elements().First().Name.LocalName;

            result.AddAnnotation(new XmlRenderHints {
                NestedResourceName = nestedResourceName
            });
            result.AddAnnotation((XElement)docNode);

            return(result);
        }
Ejemplo n.º 4
0
        public FhirInstanceTree ConstructTreeNode(XObject docNode, FhirInstanceTree parent)
        {
            var comment = (XComment)docNode;

            var result = parent.AddLastChild(COMMENT_ELEMENT_NAME, (IFluentPathValue) new TypedValue(comment.Value));

            result.AddAnnotation(new StructuralHints()
            {
                IsComment = true
            });
            result.AddAnnotation(docNode);
            return(result);
        }
        public FhirInstanceTree ConstructTreeNode(XObject docNode, FhirInstanceTree parent)
        {
            var attr = (XAttribute)docNode;

            var newNodeName = attr.Name.LocalName;
            var result      = parent.AddLastChild(newNodeName, (IValueProvider) new UntypedValue(attr.Value));

            result.AddAnnotation(new XmlRenderHints()
            {
                IsXmlAttribute = true
            });
            result.AddAnnotation(docNode);
            return(result);
        }
        public FhirInstanceTree ConstructTreeNode(XObject docNode, FhirInstanceTree parent)
        {
            var element = (XElement)docNode;

            var value  = getDivValue(element);
            var result = parent.AddLastChild(element.Name.LocalName, (IValueProvider) new ConstantValue(value));

            result.AddAnnotation(new XmlRenderHints()
            {
                IsXhtmlDiv = true
            });
            result.AddAnnotation(docNode);
            return(result);
        }
Ejemplo n.º 7
0
        public IEnumerable <XObject> SelectChildren(XObject docNode, FhirInstanceTree treeNode)
        {
            return(((XDocument)docNode).Nodes());
            //var doc = (XDocument)docNode;

            //foreach (var child in doc.Nodes())
            //{
            //    if (child is XElement && child == doc.Root)
            //    {
            //        foreach (var containedNode in doc.Root.Nodes())
            //            yield return containedNode;
            //    }
            //    else
            //        yield return child;
            //}
        }
Ejemplo n.º 8
0
        public virtual IEnumerable <XObject> SelectChildren(XObject docNode, FhirInstanceTree treeNode)
        {
            var docElement = (XElement)docNode;

            if (docElement.HasAttributes)
            {
                var attributes = getFhirNonValueAttributes(docElement);
                foreach (var attribute in attributes)
                {
                    yield return(attribute);
                }
            }

            foreach (var node in docElement.Nodes())
            {
                yield return(node);
            }
        }
        public override IEnumerable <XObject> SelectChildren(XObject docNode, FhirInstanceTree treeNode)
        {
            var children = base.SelectChildren(docNode, treeNode);

            // For a nested resource, the intermediate node (which is a child with the name of a resource) should disappear,
            // the nested nodes taking its place
            foreach (var child in children)
            {
                if (child is XElement && isNestedResource((XElement)child))
                {
                    foreach (var containedNode in ((XElement)child).Nodes())
                    {
                        yield return(containedNode);
                    }
                }
                else
                {
                    yield return(child);
                }
            }
        }
        private static FhirInstanceTree createTreeNodeFromDocNode(XObject docNode, FhirInstanceTree parent)
        {
            var handled             = false;
            FhirInstanceTree result = null;

            foreach (var strategy in STRATEGIES)
            {
                if (strategy.HandlesDocNode(docNode))
                {
                    handled = true;
                    result  = strategy.ConstructTreeNode(docNode, parent);

                    if (result != null)
                    {
                        var children = strategy.SelectChildren(docNode, result);

                        if (children != null && children.Any())
                        {
                            foreach (var child in children)
                            {
                                createTreeNodeFromDocNode(child, result);
                            }
                        }

                        strategy.PostProcess(result);
                    }

                    break;
                }
            }

            if (!handled)
            {
                throw Error.Format("Encountered unexpected node {0}, starts with \"{1}\")".
                                   FormatWith(getNodeDescription(docNode), docNode.ToString().Trim().Shorten(100)), XmlLineInfoWrapper.Wrap(docNode));
            }

            return(result);
        }
Ejemplo n.º 11
0
 public void PostProcess(FhirInstanceTree convertedNode)
 {
     return;
 }
Ejemplo n.º 12
0
 public IEnumerable <XObject> SelectChildren(XObject docNode, FhirInstanceTree treeNode)
 {
     return(null);
 }
Ejemplo n.º 13
0
 public FhirInstanceTree ConstructTreeNode(XObject docNode, FhirInstanceTree parent)
 {
     return(null);
 }