读取xml文件

上一篇 / 下一篇  2014-06-10 23:53:54 / 个人分类:selenium

方法一:
假如有这样的命名空间:namespace UI.Flight.Domestic.Online.Case.Test.BookingOrdersFunctionTest

   string tmpPath = this.GetType().Namespace.ToString();
   //UI.Flight.Domestic.Online.Case.Test.BookingOrdersFunctionTest

   int tmpPathLength = tmpPath.Split('.').Length;
//7

   string tmpFileName = this.GetType().ToString();
  //UI.Flight.Domestic.Online.Case.Test.BookingOrdersFunctionTest.TestCase_Booking_Order

   int tmpFileLength = tmpFileName.Split('.').Length;
//8
  
 path = string.Format(@"\Data\CaseData\{0}\{1}.xml", tmpPath.Split('.')[tmpPathLength - 1], tmpFileName.Split('.')[tmpFileLength - 1]);
\Data\CaseData\BookingOrdersFunctionTest\TestCase_Booking_Order.xml

方法二:

 RequestXmlPath = Path.Combine("Flight.Product", "Flight.Product.ProductWS", "FlightPolicySearchRequest", "FlightPolicySearchRequest.xml");
        private string requestXmlPath;
        protected string RequestXmlPath
        {
            set
            {
                requestXmlPath = value;
                //这时value的值为Flight.Product\Flight.Product.ProductWS\FlightPolicySearchRequest\FlightPolicySearchRequest.xml

                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, requestXmlPath);
               //这时path的值为D:\study\API.Flight\Demo\bin\Debug\Flight.Product\Flight.Product.ProductWS\FlightPolicySearchRequest\FlightPolicySearchRequest.xml

                if (File.Exists(path))
                {
                    Request = XDocument.Load(path);
                }
                else
                {
                    throw new FileNotFoundException(string.Format("文件不存在。路径:{0}", path));
                }
            }
            get
            {
                return requestXmlPath;
            }
        }


TAG:

 

评分:0

我来说两句

日历

« 2024-05-01  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 29384
  • 日志数: 27
  • 建立时间: 2014-03-18
  • 更新时间: 2014-07-10

RSS订阅

Open Toolbar