public void FnLocationtoXml() { string Constring = System.Configuration.ConfigurationManager.ConnectionStrings["LoveJourney"].ConnectionString; SqlConnection con = new SqlConnection(Constring); try { con.Open(); SqlCommand cmd = new SqlCommand("Sp_IFReports", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@TableName", "DomAirportCodes"); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet DsLoc = new DataSet(); da.Fill(DsLoc); string DirectoryPath = Server.MapPath("~/App_Data"); DirectoryInfo dir = new DirectoryInfo(DirectoryPath); if (!dir.Exists) { dir.Create(); } string filepath = "~/App_Data/" + "Airports.xml"; string DirectoryPath1 = Server.MapPath(filepath); DirectoryInfo dir1 = new DirectoryInfo(DirectoryPath1); if (!dir1.Exists) { DataSet ds1 = new DataSet(); ds1.EnforceConstraints = false; XmlDataDocument XmlDoc = new XmlDataDocument(ds1); // Write down the XML declaration XmlDeclaration xmlDeclaration = XmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); // Create the root element XmlElement rootNode = XmlDoc.CreateElement("Airports"); XmlDoc.InsertBefore(xmlDeclaration, XmlDoc.DocumentElement); XmlDoc.AppendChild(rootNode); XmlDoc.Save(Server.MapPath(filepath)); } StreamWriter XmlData = new StreamWriter(Server.MapPath("~/App_Data/" + "Airports.xml"), false); DsLoc.WriteXml(XmlData); XmlData.Close(); lblmsg.Visible = true; lblmsg.Text = " All flights list Uploaded to XML Successfully"; } finally { con.Close(); } }
public XmlDataDocument DataCollection(string mac, string ip, string hostname, string UserName,string Domain) { string result = ""; if (string.IsNullOrEmpty(mac) && string.IsNullOrEmpty(ip) && string.IsNullOrEmpty(hostname) && string.IsNullOrEmpty(UserName) && string.IsNullOrEmpty(Domain)) { result = "-2"; } else { SqlStatment.InsertData(mac, ip, hostname, UserName,Domain); result = "0"; } XmlDataDocument xd = new XmlDataDocument(); //XmlStr.Append("<?xml version=\"1.0\" encoding=\"gb2312\"?>"); XmlDeclaration newDec = xd.CreateXmlDeclaration("1.0", "gb2312", null); xd.AppendChild(newDec); XmlElement xmlElemFileName = xd.CreateElement("result"); XmlText xmlTextFileName = xd.CreateTextNode(result); xmlElemFileName.AppendChild(xmlTextFileName); xd.AppendChild(xmlElemFileName); return xd; }
public void NewInstance () { XmlDataDocument doc = new XmlDataDocument (); AssertDataSet ("#1", doc.DataSet, "NewDataSet", 0, 0); Assert.IsFalse (doc.DataSet.EnforceConstraints); XmlElement el = doc.CreateElement ("TEST"); AssertDataSet ("#2", doc.DataSet, "NewDataSet", 0, 0); Assert.IsNull (doc.GetRowFromElement (el)); doc.AppendChild (el); AssertDataSet ("#3", doc.DataSet, "NewDataSet", 0, 0); DataSet ds = new DataSet (); doc = new XmlDataDocument (ds); Assert.IsTrue (doc.DataSet.EnforceConstraints); }
public XmlDataDocument CheckClient(string mac, string ip, string hostname,string UserName,string Domain) { string result = ""; if (string.IsNullOrEmpty(mac) && string.IsNullOrEmpty(ip) && string.IsNullOrEmpty(hostname) && string.IsNullOrEmpty(Domain)) { result = "-2"; } else { DataTable dt = SqlStatment.CheckLogin(hostname, mac, Domain); result = dt.Rows[0][0].ToString(); } XmlDataDocument xd = new XmlDataDocument(); //XmlStr.Append("<?xml version=\"1.0\" encoding=\"gb2312\"?>"); XmlDeclaration newDec = xd.CreateXmlDeclaration("1.0", "gb2312", null); xd.AppendChild(newDec); XmlElement xmlElemFileName = xd.CreateElement("result"); XmlText xmlTextFileName = xd.CreateTextNode(result); xmlElemFileName.AppendChild(xmlTextFileName); xd.AppendChild(xmlElemFileName); return xd; }
private void save() { XmlDataDocument xml_doc = new XmlDataDocument (); XmlNode root = xml_doc.CreateElement ("vocab"); foreach (LessonNode l in LessonStore) { XmlNode lesson = xml_doc.CreateElement ("lesson"); XmlAttribute a_id = xml_doc.CreateAttribute ("id"); XmlAttribute a_description = xml_doc.CreateAttribute ("description"); a_id.Value = l.Id.ToString (); a_description.Value = l.Description; lesson.Attributes.Append (a_id); lesson.Attributes.Append (a_description); foreach (PairNode p in l.PairStore) { XmlNode pair = xml_doc.CreateElement ("pair"); XmlNode en = xml_doc.CreateElement ("en"); XmlNode de = xml_doc.CreateElement ("de"); en.InnerText = p.En; de.InnerText = p.De; pair.AppendChild (en); pair.AppendChild (de); lesson.AppendChild (pair); } root.AppendChild (lesson); } xml_doc.AppendChild (root); xml_doc.Save (xml_path); }
/// <summary> /// 创建数据库中已存在煤矿每笔表的xml结构 /// </summary> private static void CreateCoalTableConfig() { XmlDataDocument XmlDoc = new XmlDataDocument(); XmlElement xmlelem = XmlDoc.CreateElement("", "CoalTableConfig", ""); XmlElement xmlelemCoalCodes = XmlDoc.CreateElement("", "CoalCodes", ""); xmlelem.AppendChild(xmlelemCoalCodes); XmlDoc.AppendChild(xmlelem); XmlDoc.Save(Path_CoalConfig); }
protected void Page_Load(object sender, EventArgs e) { string httpMethod = HttpContext.Current.Request.HttpMethod.ToString(); if (httpMethod.ToUpper().ToString() == "POST") { StringBuilder sb = new StringBuilder(); int streamRead; Stream s = HttpContext.Current.Request.InputStream; Byte[] streamArray = new Byte[Convert.ToInt32(s.Length)]; streamRead = s.Read(streamArray, 0, Convert.ToInt32(s.Length)); for (int i = 0; i < Convert.ToInt32(s.Length); i++) { sb.Append(Convert.ToChar(streamArray[i])); } string strRequestBody = sb.ToString(); string[] strValues = strRequestBody.Split('&'); string travel_id = ""; string sync_reservation_ids = ""; if (strValues.Length >= 1) { if (strValues[0].ToString().Split('=')[1] != null) { sync_reservation_ids = strValues[0].ToString().Split('=')[1].ToString(); } } if (strValues.Length >= 2) { if (strValues[1].ToString().Split('=')[1] != null) { travel_id = strValues[1].ToString().Split('=')[1].ToString(); } } string DirectoryPath = Server.MapPath("~/App_Data/XMLfiles"); DirectoryInfo dir = new DirectoryInfo(DirectoryPath); if (!dir.Exists) { dir.Create(); } string filepath = "~/App_Data/XMLfiles/" + "Callback.xml"; string DirectoryPath1 = Server.MapPath(filepath); DirectoryInfo dir1 = new DirectoryInfo(DirectoryPath1); if (dir1.Exists == true) { DataSet ds1 = new DataSet(); ds1.EnforceConstraints = false; XmlDataDocument XmlDoc = new XmlDataDocument(ds1); // Write down the XML declaration // XmlDeclaration xmlDeclaration = XmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); // Create the root element XmlElement rootNode = XmlDoc.CreateElement("CallBack"); //XmlDoc.InsertBefore(xmlDeclaration, XmlDoc.DocumentElement); XmlDoc.AppendChild(rootNode); XmlDoc.Save(Server.MapPath(filepath)); } XmlTextReader refreader = new XmlTextReader(Server.MapPath("~/App_Data/XMLfiles/" + "Callback.xml")); refreader.Read(); XmlDocument Refdoc = new XmlDocument(); Refdoc.Load(refreader); refreader.Close(); string[] reservations= sync_reservation_ids.Split(','); foreach (string res in reservations) { XmlNode Refnode; XmlElement Refroot = Refdoc.DocumentElement; Refnode = Refroot.SelectSingleNode("/NewDataSet/callback[sync_reservation_ids='" + res + "']"); if (Refnode != null) { Refnode.ParentNode.RemoveChild(Refnode); } //create node and add value XmlNode node = Refdoc.CreateNode(XmlNodeType.Element, "callback", null); node.InnerXml = "<travel_id>" + travel_id + "</travel_id><sync_reservation_ids>" + res + "</sync_reservation_ids><status>" + 0 + "</status><date>" + System.DateTime.Now + "</date>"; //add to elements collection Refdoc.DocumentElement.AppendChild(node); } Refdoc.Save(Server.MapPath("~/App_Data/XMLfiles/" + "Callback.xml")); //ClsBAL obj = new ClsBAL(); // bool b = obj.BitlaCallback("", strRequestBody); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.StatusCode = 200; Response.Write("OK"); } }
private string GetWebConfigModValue(string nodeName, XmlAttributeCollection attributes) { XmlDataDocument xDoc = new XmlDataDocument(); XmlAttribute newAttribute; XmlNode modValueNode = xDoc.AppendChild(xDoc.CreateElement(nodeName)); foreach (XmlAttribute attribute in attributes) { newAttribute = xDoc.CreateAttribute(attribute.Name); newAttribute.Value = attribute.Value; modValueNode.Attributes.Append(newAttribute); } return string.Format("{0}\n", modValueNode.OuterXml); }