.Net C# 讀取xml


[TestMethod]
        public void Test3()
        {
            StringBuilder temp = new StringBuilder();
            temp.AppendFormat("<?xml version=\"1.0\"?><Entities xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
            temp.AppendFormat("<Entity>");
            temp.AppendFormat("<EntityName>EntityName</EntityName>");
            temp.AppendFormat("<IdentifyType>IdentifyType</IdentifyType>");
            temp.AppendFormat("<IdentifyNumber>IdentifyNumber</IdentifyNumber>");
            temp.AppendFormat("<IssueCountry>IssueCountry</IssueCountry>");
            temp.AppendFormat("<Role>Role</Role>");
            temp.AppendFormat("<SourceRequest>{0}</SourceRequest>", SourceRequestEnum.FCA);
            temp.AppendFormat("</Entity>");
            temp.AppendFormat("<Entity>");
            temp.AppendFormat("<EntityName>EntityName</EntityName>");
            temp.AppendFormat("<IdentifyType>IdentifyType</IdentifyType>");
            temp.AppendFormat("<IdentifyNumber>IdentifyNumber</IdentifyNumber>");
            temp.AppendFormat("<IssueCountry>IssueCountry</IssueCountry>");
            temp.AppendFormat("<Role>Role</Role>");
            temp.AppendFormat("<SourceRequest>{0}</SourceRequest>", SourceRequestEnum.FCA);
            temp.AppendFormat("</Entity>");
            temp.AppendFormat("</Entities>");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(temp.ToString());
            XmlNodeList rows = xmlDoc.SelectNodes("Entities/Entity");

            string sourceRequest = string.Empty;
            if (rows.Count > 0)
            {
                foreach (XmlNode row in rows)
                {
                    XmlNode node = row.SelectSingleNode("./SourceRequest");
                    sourceRequest = (node == null ? string.Empty : node.InnerText.Trim());
                    if (!string.IsNullOrEmpty(sourceRequest))
                    {
                        break;
                    }
                }
            }
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM