public void LXML(String s)
{
//实例化一个xml文档
XmlDocument myXmlDoc = new XmlDocument();
//加载xml文档
myXmlDoc.LoadXml(s);
//获得第一个为Computers的根节点
XmlNodeList objXmlNodes = myXmlDoc.SelectNodes("//ProductDetailInfo");
StringBuilder str = new StringBuilder();
foreach (XmlNode objXmlNode in objXmlNodes)
{
#region 基本信息
string ProductID = objXmlNode.Attributes["ProductID"].Value.ToString();
string ProductName = objXmlNode.Attributes["ProductName"].Value.ToString();
string NotApplicableDate = objXmlNode.Attributes["NotApplicableDate"].Value.ToString();
string Name = objXmlNode.Attributes["Name"].Value.ToString();
string ProductItemType = objXmlNode.Attributes["ProductItemType"].Value.ToString();
string SoldOut = objXmlNode.Attributes["SoldOut"].Value.ToString();
string IsRobItem = objXmlNode.Attributes["IsRobItem"].Value.ToString();
string AllowInvoice = objXmlNode.Attributes["AllowInvoice"].Value.ToString();
string ProductStatus = objXmlNode.Attributes["ProductStatus"].Value.ToString();
string Quantity = objXmlNode.Attributes["Quantity"].Value.ToString();
string TotalQuantity = objXmlNode.Attributes["TotalQuantity"].Value.ToString();
#endregion
#region 有效期
string saleStartDate = "";
string saleEndDate = "";
XmlNode saleNodes = objXmlNode.SelectSingleNode("SaleDateRange ");
if (saleNodes != null)
{
saleStartDate = (saleNodes.SelectSingleNode("StartDate")).InnerText.ToString();
saleEndDate = (saleNodes.SelectSingleNode("EndDate")).InnerText.ToString();
}
string tStartDate = "";
string tEndDate = "";
XmlNode tNodes = objXmlNode.SelectSingleNode("TicketEffectiveRange ");
if (tNodes != null)
{
tStartDate = (tNodes.SelectSingleNode("StartDate")).InnerText.ToString();
tEndDate = (tNodes.SelectSingleNode("EndDate")).InnerText.ToString();
}
#endregion
string groupProductSql = @"insert into group_product(supplier_product_code, project_code,product_name,supplier_code,supplier_name, settlement_cycle, state,valid_start_date,valid_end_date,sale_start_date,sale_end_date,nights, create_name, update_name) values('" + ProductID + "','2','"+ Name + "','2','XX','2','"+0+"','"+ saleStartDate + "','"+ saleEndDate + "','"+ tStartDate + "','"+ tEndDate + "','1','chb','chb'); ";
#region 价格信息
XmlNode priceNodes = objXmlNode.SelectSingleNode("ProductPrice");
string VendorPrice = "";
string SalePrice = "";
string weekStr = "";
string str1 = "";
string str2 = "";
if (priceNodes != null)
{
//SalePrice = (priceNodes.SelectSingleNode("SalePrice")).Attributes["Price"].Value.ToString();
XmlNodeList changePriceNodes = priceNodes.SelectNodes("ChangePriceList");
foreach (XmlNode priceNode in changePriceNodes)
{
str1 = "";
VendorPrice = priceNode.Attributes["VendorPrice"].Value.ToString();
SalePrice = priceNode.Attributes["SalePrice"].Value.ToString();
XmlNode weekNode = priceNode.SelectSingleNode("WeekList");
if (weekNode != null)
{
XmlNodeList intNodeList = weekNode.ChildNodes;
if (intNodeList != null)
{
string week = "";
weekStr = "";
foreach (XmlNode intNode in intNodeList)
{
//week = (intNode.SelectSingleNode("int")).InnerText;
week = "周" + intNode.InnerText.ToString();
weekStr = weekStr + week;
}
}
}
str1 = "卖价:" + SalePrice + "底价:" + VendorPrice + "星期:" + weekStr;
str2 = str2 + str1;
}
}
#endregion
#region 地址信息
string HotelName = "";
string ProvinceName = "";
string CityID = "";
string CityName = "";
string LocationName = "";
string Address = "";
string LON = "";
string LAT = "";
string resouceAddress = "" ;
XmlNode productItemNode = objXmlNode.SelectSingleNode("ProductItem");
if (productItemNode != null)
{
XmlNode hotelinfoNodes = productItemNode.SelectSingleNode("HotelItemList");
if (hotelinfoNodes != null)
{
HotelName = (hotelinfoNodes.SelectSingleNode("HotelInfo")).Attributes["Name"].Value.ToString();
XmlNode hotelinfoNode = hotelinfoNodes.SelectSingleNode("HotelInfo");
if (hotelinfoNode != null)
{
//ProvinceName = (hotelinfoNode.SelectSingleNode("Province")).Attributes["ProvinceName"].Value.ToString();
CityName = (hotelinfoNode.SelectSingleNode("City")).Attributes["CityName"].Value.ToString();
CityID = (hotelinfoNode.SelectSingleNode("City")).Attributes["CityID"].Value.ToString();
LocationName = (hotelinfoNode.SelectSingleNode("Location")).Attributes["LocationName"].Value.ToString();
Address = (hotelinfoNode.SelectSingleNode("AddressInfo")).Attributes["Address"].Value.ToString();
XmlNode positionNode = hotelinfoNode.SelectSingleNode("Position");
if (positionNode != null)
{
LON = (positionNode.SelectSingleNode("LON")).InnerText.ToString();
LAT = (positionNode.SelectSingleNode("LAT")).InnerText.ToString();
}
}
}
resouceAddress = ProvinceName.Trim() + CityName.Trim() + LocationName.Trim() + Address.Trim();
}
#endregion
string groupResourceSql = @"insert into group_resource(project_code, resource_name, ctrip_city_id, city_name, address, baidu_lon, baidu_lat, state, create_name, update_name) values('2','"+ resouceAddress + "','"+CityID+"','"+CityName+"','"+resouceAddress+"','"+LON+"','"+LAT+"',0,'chb','chb');";
//XmlNode scoreNodes = objXmlNode.SelectSingleNode("ProductScores");
//string CtripStar = "";
//string StarRate = "";
//string CommentScore = "";
//if (scoreNodes != null)
//{
// CtripStar = scoreNodes.Attributes["CtripStar"].Value.ToString();
// StarRate = scoreNodes.Attributes["StarRate"].Value.ToString();
// CommentScore = (scoreNodes.SelectSingleNode("CommentScore")).InnerText.ToString();
//}
str.Append(groupProductSql);
str.Append("\r\n");
str.Append(groupResourceSql);
str.Append("\r\n");
}
FileStream fileStream = new FileStream(@"D:\XX\1.txt", FileMode.Append);
StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.Default);
streamWriter.Write(str + "\r\n");
streamWriter.Flush();
streamWriter.Close();
fileStream.Close();
}