欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# 读取XML

程序员文章站 2022-07-04 23:04:27
C# 读取XML ......

c# 读取xml

string xml = "<rowid>
          <row>
            <patname>刘荣胜</patname>
            <sex>1</sex>
            <age>50岁</age>
            <examid>16377042||8</examid>
            <patientid>16543990</patientid>
            <lodgedept>消化内科</lodgedept>
            <lodgedoctor>陆德云</lodgedoctor>
            <bedno>+28</bedno>
            <outhosno>op0013927016</outhosno>
            <inhosno></inhosno>
            <birthday>1968-12-10</birthday>
            <clinicdiag>测试临床诊断</clinicdiag>
            <oeoridate>2019-08-18</oeoridate>
          </row>
          <row>
            <patname>刘荣胜</patname>
            <sex>1</sex>
            <age>50岁</age>
            <examid>16377042||7</examid>
            <patientid>16543990</patientid>
            <lodgedept>消化内科</lodgedept>
            <lodgedoctor>陆德云</lodgedoctor>
            <bedno>无床号</bedno>
            <outhosno>op0013927016</outhosno>
            <inhosno></inhosno>
            <birthday>1968-12-10</birthday>
            <clinicdiag>慢性胃炎;肠道功能紊乱</clinicdiag>
            <oeoridate>2019-08-08</oeoridate>
          </row>
        </rowid>";
xmldocument xmldoc = new xmldocument();

            xmldoc.loadxml(xml);

            datetime date = convert.todatetime("2018-01-01");

            xmlnodelist patinfo = xmldoc.selectnodes("rowid//row");
            foreach (xmlelement element in patinfo)
            {
                datetime dt = convert.todatetime(element.getelementsbytagname("oeoridate")[0].innertext);
                if (dt>date)
                {
                    date = convert.todatetime(element.getelementsbytagname("oeoridate")[0].innertext);

                    textbox1.text = element.getelementsbytagname("patientid")[0].innertext;

                    textbox2.text = element.getelementsbytagname("patname")[0].innertext;
                    textbox3.text = element.getelementsbytagname("sex")[0].innertext;
                    textbox4.text = element.getelementsbytagname("age")[0].innertext;
                    textbox12.text = element.getelementsbytagname("examid")[0].innertext;
                    textbox6.text = element.getelementsbytagname("inhosno")[0].innertext;

                    textbox5.text = element.getelementsbytagname("birthday")[0].innertext;

                    textbox7.text = element.getelementsbytagname("outhosno")[0].innertext;
                    textbox8.text = element.getelementsbytagname("bedno")[0].innertext;
                    textbox9.text = element.getelementsbytagname("clinicdiag")[0].innertext;
                    textbox10.text = element.getelementsbytagname("lodgedept")[0].innertext;
                    textbox11.text = element.getelementsbytagname("lodgedoctor")[0].innertext;
                }              
            }