示例#1
0
        private static IEnumerable <XAttribute> getFhirNonValueAttributes(XElement node)
        {
            foreach (var attr in node.Attributes())
            {
                // skip fhir "value" attribute
                if (attr.Name == XVALUE)
                {
                    continue;
                }

                // skip xmlns declarations
                if (attr.IsNamespaceDeclaration)
                {
                    continue;
                }

#if MOVED_TO_FHIR_ASSEMBLY
                // skip xmlns:xsi declaration
                if (attr.Name == XName.Get("{http://www.w3.org/2000/xmlns/}xsi") && !SerializationConfig.EnforceNoXsiAttributesOnRoot)
                {
                    continue;
                }

                // skip schemaLocation
                if (attr.Name == XName.Get("{http://www.w3.org/2001/XMLSchema-instance}schemaLocation") && !SerializationConfig.EnforceNoXsiAttributesOnRoot)
                {
                    continue;
                }
#else
                // skip xmlns:xsi declaration
                if (attr.Name == XName.Get("{http://www.w3.org/2000/xmlns/}xsi"))
                {
                    continue;
                }

                // skip schemaLocation
                if (attr.Name == XName.Get("{http://www.w3.org/2001/XMLSchema-instance}schemaLocation"))
                {
                    continue;
                }
#endif
                if (attr.Name.NamespaceName == "")
                {
                    yield return(attr);
                }
                else
                {
                    throw Error.Format("Encountered unexpected attribute '{0}'.".FormatWith(attr.Name), XmlLineInfoWrapper.Wrap(attr));
                }
            }
        }
        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);
        }