qq_20368267
一片CT
采纳率100%
2019-06-28 15:41

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

40

xml地址

取这几个值吧

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 2年前
    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 . . .

    图片说明

    点赞 评论 复制链接分享