示例#1
0
 public static void ProcessPrepopulatedValues(IEnumerable <ITypedElement> prepopulatedValues, Func <string, string, string> AppendXmlFramentResults, Action <string, bool, string> AppendResults)
 {
     if (prepopulatedValues.Count() > 0)
     {
         foreach (var item in prepopulatedValues)
         {
             string tooltip = item.Annotation <IShortPathGenerator>()?.ShortPath;
             if (item is stu3.Hl7.Fhir.ElementModel.IFhirValueProvider)
             {
                 foreach (var t2 in fp3.ElementNavFhirExtensions.ToFhirValues(new ITypedElement[] { item }).Where(i => i != null))
                 {
                     // output the content as XML fragments
                     var fragment = new stu3.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(t2, root: t2.TypeName);
                     fragment = AppendXmlFramentResults(fragment, tooltip);
                 }
             }
             else if (item is dstu2.Hl7.Fhir.ElementModel.IFhirValueProvider)
             {
                 foreach (var t2 in fp2.ElementNavFhirExtensions.ToFhirValues(new ITypedElement[] { item }).Where(i => i != null))
                 {
                     // output the content as XML fragments
                     var fragment = new dstu2.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(t2, root: t2.TypeName);
                     fragment = AppendXmlFramentResults(fragment, tooltip);
                 }
             }
             else if (item is r4.Hl7.Fhir.ElementModel.IFhirValueProvider)
             {
                 foreach (var t2 in fp4.ElementNavFhirExtensions.ToFhirValues(new ITypedElement[] { item }).Where(i => i != null))
                 {
                     // output the content as XML fragments
                     var fragment = new r4.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(t2, root: t2.TypeName);
                     fragment = AppendXmlFramentResults(fragment, tooltip);
                 }
             }
             else if (item is ITypedElement te)
             {
                 AppendResults($"<{te.InstanceType} value=\"{te.Value}\">", false, null);
             }
         }
     }
 }
示例#2
0
        public static void PretifyXML(string text, Action <string> setText)
        {
            // prettify the XML (and convert to XML if it wasn't already)
            f3.Resource resource = null;
            string      contentAsXML;

            try
            {
                if (text.StartsWith("{"))
                {
                    resource     = new stu3.Hl7.Fhir.Serialization.FhirJsonParser().Parse <f3.Resource>(text);
                    contentAsXML = new stu3.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(resource);
                }
                else
                {
                    contentAsXML = text;
                }
                var doc = System.Xml.Linq.XDocument.Parse(contentAsXML);
                setText(doc.ToString(System.Xml.Linq.SaveOptions.None));
            }
            catch (Exception ex3)
            {
                f2.Resource resource2 = null;
                try
                {
                    if (text.StartsWith("{"))
                    {
                        resource2    = new dstu2.Hl7.Fhir.Serialization.FhirJsonParser().Parse <f2.Resource>(text);
                        contentAsXML = new dstu2.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(resource2);
                    }
                    else
                    {
                        contentAsXML = text;
                    }
                    var doc = System.Xml.Linq.XDocument.Parse(contentAsXML);
                    setText(doc.ToString(System.Xml.Linq.SaveOptions.None));
                }
                catch (Exception ex2)
                {
                    f4.Resource resource4 = null;
                    try
                    {
                        if (text.StartsWith("{"))
                        {
                            resource4    = new r4.Hl7.Fhir.Serialization.FhirJsonParser().Parse <f4.Resource>(text);
                            contentAsXML = new r4.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(resource4);
                        }
                        else
                        {
                            contentAsXML = text;
                        }
                        var doc = System.Xml.Linq.XDocument.Parse(contentAsXML);
                        setText(doc.ToString(System.Xml.Linq.SaveOptions.None));
                    }
                    catch (Exception ex4)
                    {
                        System.Diagnostics.Debug.WriteLine(ex4.Message);
                        System.Diagnostics.Debug.WriteLine(ex3.Message);
                        System.Diagnostics.Debug.WriteLine(ex2.Message);
                    }
                }
            }
        }