一片CT 2019-06-28 15:41 采纳率: 100%
浏览 506

求C#解析这个xml最简单,实用的方法

xml地址

取这几个值吧

图片说明图片说明图片说明图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-06-29 19:45
    关注
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    
    namespace Q767525
    {
        class Program
        {
            static void Main(string[] args)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("https://t-webservice.oss-cn-beijing.aliyuncs.com/1232165648.xml");
                var subjectDemographicPerson = doc.GetElementsByTagName("subjectDemographicPerson")[0];
                var name = subjectDemographicPerson.ChildNodes.Cast<XmlNode>().First(x => x.Name == "name").InnerText;
                Console.WriteLine(name);
                var administrativeGenderCode = subjectDemographicPerson.ChildNodes.Cast<XmlNode>().First(x => x.Name == "administrativeGenderCode");
                var code = administrativeGenderCode.Attributes["code"].Value;
                Console.WriteLine(code);
                var codeSystem = administrativeGenderCode.Attributes["codeSystem"].Value;
                Console.WriteLine(codeSystem);
                var effectiveTime = doc.GetElementsByTagName("effectiveTime")[0];
                Console.WriteLine(effectiveTime.FirstChild.Attributes["value"].Value);
                var annotationlist = doc.GetElementsByTagName("annotation");
                foreach (XmlNode item in annotationlist)
                {
                    Console.WriteLine(item.FirstChild.Attributes["code"].Value);
                    var itemvalue = item.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "value");
                    if (itemvalue != null)
                    {
                        Console.WriteLine("\t" + itemvalue.Attributes["xsi:type"].Value);
                        if (itemvalue.Attributes.Cast<XmlAttribute>().Any(x => x.Name == "unit"))
                            Console.WriteLine("\t" + itemvalue.Attributes["unit"].Value);
                        if (!string.IsNullOrEmpty(itemvalue.InnerText))
                            Console.WriteLine("\t" + itemvalue.InnerText);
                        else
                            Console.WriteLine("\t" + itemvalue.Attributes["value"]);
                    }
                }
            }
        }
    }
    
    

    张帅
    M
    2.16.840.1.113883.5.1
    20190626102804
    MDC_ECG_HEART_RATE
    PQ
    bpm
    System.Xml.XmlAttribute
    MDC_ECG_TIME_PD_PR
    PQ
    ms
    System.Xml.XmlAttribute
    MDC_ECG_TIME_PD_QRS
    PQ
    ms
    System.Xml.XmlAttribute
    MDC_ECG_TIME_PD_QT
    PQ
    ms
    System.Xml.XmlAttribute
    MDC_ECG_TIME_PD_QTc
    PQ
    ms
    System.Xml.XmlAttribute
    MDC_ECG_ANGLE_P_FRONT
    PQ
    deg
    System.Xml.XmlAttribute
    MDC_ECG_ANGLE_QRS_FRONT
    PQ
    deg
    System.Xml.XmlAttribute
    MDC_ECG_ANGLE_T_FRONT
    PQ
    deg
    System.Xml.XmlAttribute
    ZONCARE_ECG_RV5
    PQ
    mv
    System.Xml.XmlAttribute
    ZONCARE_ECG_SV1
    PQ
    mv
    System.Xml.XmlAttribute
    MDC_ECG_INTERPRETATION
    MDC_ECG_INTERPRETATION_STATEMENT
    ST
    窦性心动过缓
    MDC_ECG_INTERPRETATION_STATEMENT
    ST
    除心率外的正常心电图
    Press any key to continue . . .

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable