首页 > 编程语言 >C#解析XML字符串

C#解析XML字符串

时间:2022-12-21 13:22:22浏览次数:45  
标签:XML nodelist string C# GetElementsByTagName po 字符串 dr xmlDoc

string sql = "实际sql语句";
            DataTable sourseDt = OracleHelper.ExecuteDataTable(sql);
            for(var i = 0;i < sourseDt.Rows.Count; i++)
            {
                string sourceCont = sourseDt.Rows[i]["FIELDVALUES"].ToString();

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(sourceCont);
                //取so
                XmlNodeList nodelist = xmlDoc.GetElementsByTagName("oea01");
                string so = nodelist[0].InnerText;
         //取po
                    nodelist = xmlDoc.GetElementsByTagName("oea10");
                    string po = nodelist[0].InnerText;

                    //取单身
                    nodelist = xmlDoc.GetElementsByTagName("s_oeb");
                    string sourceGrid = nodelist[0].InnerXml;
                    xmlDoc.LoadXml(sourceGrid);
                    //单身用record,可能多条
                    nodelist = xmlDoc.GetElementsByTagName("record");
                    foreach (XmlNode pnode in nodelist)
                    {
                        DataRow dr = dt.NewRow();
                        dr["so"] = so;
                        dr["po"] = po;
                        for (var k = 0; k < pnode.ChildNodes.Count; k++)
                        {
                            XmlNode sonNode = pnode.ChildNodes[k];
                            string key = sonNode.Attributes.GetNamedItem("id").Value;
                            string value = sonNode.InnerText.ToString();
                            int res = Array.IndexOf(needKey, key);
                            if (res > -1)
                            {
                                dr[key] = value;
                            }
                        }
                        dt.Rows.Add(dr);

                    }
                           
            }

 

标签:XML,nodelist,string,C#,GetElementsByTagName,po,字符串,dr,xmlDoc
From: https://www.cnblogs.com/ydc2023/p/16996023.html

相关文章