Example #1
0
        // [WMR 20160421] Caller is responsible for disposing reader
        public Base Parse(XmlReader reader, Type dataType)
        {
            if (dataType == null)
            {
                throw Error.ArgumentNull(nameof(dataType));
            }

            var xmlReader = new XmlDomFhirReader(reader, Settings.DisallowXsiAttributesOnRoot);

            return(Parse(xmlReader, dataType));
        }
Example #2
0
        private static Resource getContents(XElement content)
        {
            string contentType = SerializationUtil.StringValueOrNull(content.Attribute(XATOM_CONTENT_TYPE));

            if (contentType != "text/xml")
            {
                throw Error.Format("Entry should have contents of type 'text/xml'", XmlDomFhirReader.GetLineInfo(content));
            }

            XElement resource = null;

            try
            {
                resource = content.Elements().Single();
            }
            catch
            {
                throw Error.Format("Entry <content> node should have a single child: the resource", XmlDomFhirReader.GetLineInfo(content));
            }

            return((Resource)(new ResourceReader(new XmlDomFhirReader(resource)).Deserialize()));
        }
Example #3
0
        private static Resource getContents(XElement content)
        {
            string contentType = SerializationUtil.StringValueOrNull(content.Attribute(XATOM_CONTENT_TYPE));

            if (contentType != "text/xml" && contentType != "application/xml+fhir")
            {
                throw Error.Format("Bundle Entry should have contents of type 'text/xml'", XmlDomFhirReader.GetLineInfo(content));
            }

#if DEBUG
            if (contentType == "application/xml+fhir")
            {
                System.Diagnostics.Debug.WriteLine("Bundle Entry should have contents of type 'text/xml'", XmlDomFhirReader.GetLineInfo(content));
            }
#endif

            XElement resource = null;

            try
            {
                resource = content.Elements().Single();
            }
            catch
            {
                throw Error.Format("Entry <content> node should have a single child: the resource", XmlDomFhirReader.GetLineInfo(content));
            }

            return((Resource)(new ResourceReader(new XmlDomFhirReader(resource)).Deserialize()));
        }
Example #4
0
        private static BundleEntry loadEntry(XElement entry)
        {
            BundleEntry result;

            try
            {
                if (entry.Name == XTOMBSTONE + XATOM_DELETED_ENTRY)
                {
                    result    = new DeletedEntry();
                    result.Id = SerializationUtil.UriValueOrNull(entry.Attribute(XATOM_DELETED_REF));
                }
                else
                {
                    XElement content = entry.Element(XATOMNS + XATOM_CONTENT);
                    var      id      = SerializationUtil.UriValueOrNull(entry.Element(XATOMNS + XATOM_ID));

                    if (content != null)
                    {
                        var parsed = getContents(content);
                        if (parsed != null)
                        {
                            result = ResourceEntry.Create(parsed);
                        }
                        else
                        {
                            throw Error.Format("BundleEntry has a content element without content", XmlDomFhirReader.GetLineInfo(content));
                        }
                    }
                    else
                    {
                        result = SerializationUtil.CreateResourceEntryFromId(id);
                    }

                    result.Id = id;
                }

                result.Links = getLinks(entry.Elements(XATOMNS + XATOM_LINK));
                result.Tags  = TagListParser.ParseTags(entry.Elements(XATOMNS + XATOM_CATEGORY));

                if (result is DeletedEntry)
                {
                    ((DeletedEntry)result).When = SerializationUtil.InstantOrNull(entry.Attribute(XATOM_DELETED_WHEN));
                }
                else
                {
                    ResourceEntry re = (ResourceEntry)result;
                    re.Title       = SerializationUtil.StringValueOrNull(entry.Element(XATOMNS + XATOM_TITLE));
                    re.LastUpdated = SerializationUtil.InstantOrNull(entry.Element(XATOMNS + XATOM_UPDATED));
                    re.Published   = SerializationUtil.InstantOrNull(entry.Element(XATOMNS + XATOM_PUBLISHED));
                    re.AuthorName  = entry.Elements(XATOMNS + XATOM_AUTHOR).Count() == 0 ? null :
                                     SerializationUtil.StringValueOrNull(entry.Element(XATOMNS + XATOM_AUTHOR)
                                                                         .Element(XATOMNS + XATOM_AUTH_NAME));
                    re.AuthorUri = entry.Elements(XATOMNS + XATOM_AUTHOR).Count() == 0 ? null :
                                   SerializationUtil.StringValueOrNull(entry.Element(XATOMNS + XATOM_AUTHOR)
                                                                       .Element(XATOMNS + XATOM_AUTH_URI));
                }
            }
            catch (Exception exc)
            {
                throw Error.Format("Exception while reading entry: " + exc.Message, XmlDomFhirReader.GetLineInfo(entry));
            }

            return(result);
        }
Example #5
0
        public static Base Parse(XmlReader reader, Type dataType = null)
        {
            var xmlReader = new XmlDomFhirReader(reader);

            return(Parse(xmlReader));
        }