CreateElement() public method

Creates an element with the specified Prefix, LocalName, and NamespaceURI.
public CreateElement ( string prefix, string localName, string namespaceURI ) : XmlElement
prefix string
localName string
namespaceURI string
return XmlElement
示例#1
0
        public void AddLink(string title, string uri)
        {
            XmlDocument doc = new XmlDataDocument();
            doc.Load("RssLinks.xml");
            XmlNode rootNode = doc.SelectSingleNode("links");

            XmlNode linkNode = doc.CreateElement("link");

            XmlNode titleNode = doc.CreateElement("title");
            XmlText titleText = doc.CreateTextNode(title);
            titleNode.AppendChild(titleText);

            XmlNode uriNode = doc.CreateElement("uri");
            XmlText uriText = doc.CreateTextNode(uri);
            uriNode.AppendChild(uriText);

            XmlNode defaultshowNode = doc.CreateElement("defaultshow");
            XmlText defaultshowText = doc.CreateTextNode("false");
            defaultshowNode.AppendChild(defaultshowText);

            linkNode.AppendChild(titleNode);
            linkNode.AppendChild(uriNode);
            linkNode.AppendChild(defaultshowNode);

            rootNode.AppendChild(linkNode);

            doc.Save("RssLinks.xml");
        }
    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();
        }
    }
示例#3
0
		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);
		}
示例#4
0
        /// <summary>
        /// Sets the application configuration setting.
        /// </summary>
        /// <param name="setting">Setting to be changed/added.</param>
        /// <param name="val">Value to change/add.</param>
        public static void SetValue(string setting, string val)
        {
            bool changed = false;

            System.Reflection.Assembly asm = System.Reflection.Assembly.GetEntryAssembly();
            System.IO.FileInfo         fi  = new System.IO.FileInfo(asm.Location + ".config");
            System.Xml.XmlDataDocument doc = new System.Xml.XmlDataDocument();
            try
            {
                //Load the XML application configuration file
                doc.Load(fi.FullName);
                //Loops through the nodes to find the target node to change
                foreach (System.Xml.XmlNode node in doc["configuration"]["appSettings"])
                {
                    if (node.Name == "add")
                    {
                        //Set the key and value attributes
                        if (node.Attributes.GetNamedItem("key").Value == setting)
                        {
                            node.Attributes.GetNamedItem("value").Value = val;
                            //Flag the change as complete
                            changed = true;
                        }
                    }
                }
                //If not changed yet then we assume it's a new key to be added
                if (!changed)
                {
                    //create the new node and append it to the collection
                    System.Xml.XmlNode      node    = doc["configuration"]["appSettings"];
                    System.Xml.XmlElement   elem    = doc.CreateElement("add");
                    System.Xml.XmlAttribute attrKey = doc.CreateAttribute("key");
                    System.Xml.XmlAttribute attrVal = doc.CreateAttribute("value");
                    elem.Attributes.SetNamedItem(attrKey).Value = setting;
                    elem.Attributes.SetNamedItem(attrVal).Value = val;
                    node.AppendChild(elem);
                }
                //Save the XML configuration file.
                doc.Save(fi.FullName);
            }
            catch
            {
                //There was an error loading or reading the config file...throw an error.
                throw new Exception("Unable to set the value.  Check that the configuration file exists and contains the appSettings element.");
            }
        }
示例#5
0
        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;
        }
示例#6
0
        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;
        }
示例#7
0
 public string EncodeXml()
 {
     XmlDataDocument myXMLobj = new XmlDataDocument();
      XmlElement myXML = myXMLobj.CreateElement("items");
      EncodeNodes(Items, myXML, myXMLobj);
      return myXML.OuterXml;
 }
示例#8
0
        public void Test6()
        {
            DataSet RegionDS = new DataSet();

            RegionDS.ReadXmlSchema(new StringReader(RegionXsd));
            XmlDataDocument DataDoc = new XmlDataDocument(RegionDS);
            DataDoc.Load(new StringReader(RegionXml));
            DataDoc.DataSet.EnforceConstraints = false;

            XmlElement newNode = DataDoc.CreateElement("Region");
            XmlElement newChildNode = DataDoc.CreateElement("RegionID");

            newChildNode.InnerText = "64";
            XmlElement newChildNode2 = null;
            try
            {
                newChildNode2 = DataDoc.CreateElement("something else");
                Assert.False(true);
            }
            catch (XmlException)
            {
            }
            newChildNode2 = DataDoc.CreateElement("something_else");

            newChildNode2.InnerText = "test node";

            newNode.AppendChild(newChildNode);
            newNode.AppendChild(newChildNode2);
            DataDoc.DocumentElement.AppendChild(newNode);

            TextWriter text = new StringWriter();

            //DataDoc.Save (text);
            DataDoc.DataSet.WriteXml(text);
            string TextString = text.ToString();
            string substring = TextString.Substring(0, TextString.IndexOf("\n") - 1);
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);

            for (int i = 0; i < 21; i++)
            {
                substring = TextString.Substring(0, TextString.IndexOf("\n"));
                TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            }

            Assert.True(substring.IndexOf("  <Region>") != -1);

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            Assert.True(substring.IndexOf("    <RegionID>64</RegionID>") != -1);

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            Assert.True(substring.IndexOf("  </Region>") != -1);

            substring = TextString.Substring(0, TextString.Length);
            Assert.True(substring.IndexOf("</Root>") != -1);
        }
示例#9
0
        public void Test5()
        {
            DataSet RegionDS = new DataSet();

            RegionDS.ReadXmlSchema(new StringReader(RegionXsd));
            XmlDataDocument DataDoc = new XmlDataDocument(RegionDS);
            DataDoc.Load(new StringReader(RegionXml));
            try
            {
                DataDoc.DocumentElement.AppendChild(DataDoc.DocumentElement.FirstChild);
                Assert.False(true);
            }
            catch (InvalidOperationException e)
            {
                Assert.Equal(typeof(InvalidOperationException), e.GetType());
                Assert.Equal("Please set DataSet.EnforceConstraints == false before trying to edit XmlDataDocument using XML operations.", e.Message);
                DataDoc.DataSet.EnforceConstraints = false;
            }
            XmlElement newNode = DataDoc.CreateElement("Region");
            XmlElement newChildNode = DataDoc.CreateElement("RegionID");
            newChildNode.InnerText = "64";
            XmlElement newChildNode2 = DataDoc.CreateElement("RegionDescription");
            newChildNode2.InnerText = "test node";
            newNode.AppendChild(newChildNode);
            newNode.AppendChild(newChildNode2);
            DataDoc.DocumentElement.AppendChild(newNode);
            TextWriter text = new StringWriter();

            //DataDoc.Save (text);
            DataDoc.DataSet.WriteXml(text);
            string TextString = text.ToString();
            string substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);

            for (int i = 0; i < 21; i++)
            {
                substring = TextString.Substring(0, TextString.IndexOf("\n"));
                TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            }
            Assert.True(substring.IndexOf("  <Region>") != -1);

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            Assert.True(substring.IndexOf("    <RegionID>64</RegionID>") != -1);

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            Assert.True(substring.IndexOf("    <RegionDescription>test node</RegionDescription>") != -1);

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            Assert.True(substring.IndexOf("  </Region>") != -1);

            substring = TextString.Substring(0, TextString.Length);
            Assert.True(substring.IndexOf("</Root>") != -1);
        }
示例#10
0
        public void CreateElement3()
        {
            XmlDataDocument doc = new XmlDataDocument();
            doc.DataSet.ReadXmlSchema(new StringReader(RegionXsd));
            doc.Load(new StringReader(RegionXml));

            XmlElement Element = doc.CreateElement("ElementName", "namespace");
            Assert.Equal(string.Empty, Element.Prefix);
            Assert.Equal("ElementName", Element.LocalName);
            Assert.Equal("namespace", Element.NamespaceURI);

            Element = doc.CreateElement("prefix:ElementName", "namespace");
            Assert.Equal("prefix", Element.Prefix);
            Assert.Equal("ElementName", Element.LocalName);
            Assert.Equal("namespace", Element.NamespaceURI);
        }
示例#11
0
        public void CreateElement1()
        {
            XmlDataDocument doc = new XmlDataDocument();
            doc.DataSet.ReadXmlSchema(new StringReader(RegionXsd));
            doc.Load(new StringReader(RegionXml));

            XmlElement Element = doc.CreateElement("prefix", "localname", "namespaceURI");
            Assert.Equal("prefix", Element.Prefix);
            Assert.Equal("localname", Element.LocalName);
            Assert.Equal("namespaceURI", Element.NamespaceURI);
            doc.ImportNode(Element, false);

            TextWriter text = new StringWriter();
            doc.Save(text);

            string substring = string.Empty;
            string TextString = text.ToString();

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            Assert.True(substring.IndexOf("<Root>") != -1);

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            Assert.True(substring.IndexOf("  <Region>") != -1);

            substring = TextString.Substring(0, TextString.IndexOf("\n"));
            TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            Assert.True(substring.IndexOf("    <RegionID>1</RegionID>") != -1);

            for (int i = 0; i < 26; i++)
            {
                substring = TextString.Substring(0, TextString.IndexOf("\n"));
                TextString = TextString.Substring(TextString.IndexOf("\n") + 1);
            }

            substring = TextString.Substring(0, TextString.Length);
            Assert.True(substring.IndexOf("</Root>") != -1);
        }
示例#12
0
		public void TestCreateElementAndRow ()
		{
			DataSet ds = new DataSet ("set");
			DataTable dt = new DataTable ("tab1");
			dt.Columns.Add ("col1");
			dt.Columns.Add ("col2");
			ds.Tables.Add (dt);
			DataTable dt2 = new DataTable ("child");
			dt2.Columns.Add ("ref");
			dt2.Columns.Add ("val");
			ds.Tables.Add (dt2);
			DataRelation rel = new DataRelation ("rel",
				dt.Columns [0], dt2.Columns [0]);
			rel.Nested = true;
			ds.Relations.Add (rel);
			XmlDataDocument doc = new XmlDataDocument (ds);
			doc.LoadXml ("<set><tab1><col1>1</col1><col2/><child><ref>1</ref><val>aaa</val></child></tab1></set>");
			AssertEquals (1, ds.Tables [0].Rows.Count);
			AssertEquals (1, ds.Tables [1].Rows.Count);

			// document element - no mapped row
			XmlElement el = doc.DocumentElement;
			AssertNull (doc.GetRowFromElement (el));

			// tab1 element - has mapped row
			el = el.FirstChild as XmlElement;
			DataRow row = doc.GetRowFromElement (el);
			AssertNotNull (row);
			AssertEquals (DataRowState.Added, row.RowState);

			// col1 - it is column. no mapped row
			el = el.FirstChild as XmlElement;
			row = doc.GetRowFromElement (el);
			AssertNull (row);

			// col2 - it is column. np mapped row
			el = el.NextSibling as XmlElement;
			row = doc.GetRowFromElement (el);
			AssertNull (row);

			// child - has mapped row
			el = el.NextSibling as XmlElement;
			row = doc.GetRowFromElement (el);
			AssertNotNull (row);
			AssertEquals (DataRowState.Added, row.RowState);

			// created (detached) table 1 element (used later)
			el = doc.CreateElement ("tab1");
			row = doc.GetRowFromElement (el);
			AssertEquals (DataRowState.Detached, row.RowState);
			AssertEquals (1, dt.Rows.Count); // not added yet

			// adding a node before setting EnforceConstraints
			// raises an error
			try {
				doc.DocumentElement.AppendChild (el);
				Fail ("Invalid Operation should occur; EnforceConstraints prevents addition.");
			} catch (InvalidOperationException) {
			}

			// try again...
			ds.EnforceConstraints = false;
			AssertEquals (1, dt.Rows.Count); // not added yet
			doc.DocumentElement.AppendChild (el);
			AssertEquals (2, dt.Rows.Count); // added
			row = doc.GetRowFromElement (el);
			AssertEquals (DataRowState.Added, row.RowState); // changed

			// Irrelevant element
			XmlElement el2 = doc.CreateElement ("hoge");
			row = doc.GetRowFromElement (el2);
			AssertNull (row);

			// created table 2 element (used later)
			el = doc.CreateElement ("child");
			row = doc.GetRowFromElement (el);
			AssertEquals (DataRowState.Detached, row.RowState);

			// Adding it to irrelevant element performs no row state change.
			AssertEquals (1, dt2.Rows.Count); // not added yet
			el2.AppendChild (el);
			AssertEquals (1, dt2.Rows.Count); // still not added
			row = doc.GetRowFromElement (el);
			AssertEquals (DataRowState.Detached, row.RowState); // still detached here
		}
示例#13
0
 /// <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);
 }
示例#14
0
		public void CreateElement3 ()
		{
			XmlDataDocument doc = new XmlDataDocument ();
			doc.DataSet.ReadXmlSchema ("Test/System.Xml/region.xsd");
			doc.Load ("Test/System.Xml/region.xml");
			
			XmlElement Element = doc.CreateElement ("ElementName", "namespace");
			Assert.AreEqual (string.Empty, Element.Prefix, "test#01");
			Assert.AreEqual ("ElementName", Element.LocalName, "test#02");
			Assert.AreEqual ("namespace", Element.NamespaceURI, "test#03");
			
			Element = doc.CreateElement ("prefix:ElementName", "namespace");
			Assert.AreEqual ("prefix", Element.Prefix, "test#04");
			Assert.AreEqual ("ElementName", Element.LocalName, "test#05");
			Assert.AreEqual ("namespace", Element.NamespaceURI, "test#06");
		}
		public void CreateElement3 ()
		{
			XmlDataDocument doc = new XmlDataDocument ();
			doc.DataSet.ReadXmlSchema ("Test/System.Xml/region.xsd");
			doc.Load ("Test/System.Xml/region.xml");
			
			XmlElement Element = doc.CreateElement ("ElementName", "namespace"); 			
			AssertEquals ("test#01", "", Element.Prefix);
			AssertEquals ("test#02", "ElementName", Element.LocalName);
			AssertEquals ("test#03", "namespace", Element.NamespaceURI);
			
			Element = doc.CreateElement ("prefix:ElementName", "namespace");
			AssertEquals ("test#04", "prefix", Element.Prefix);
			AssertEquals ("test#05", "ElementName", Element.LocalName);
			AssertEquals ("test#06", "namespace", Element.NamespaceURI);
		}
示例#16
0
 /// <summary>
 /// Sets the application configuration setting.
 /// </summary>
 /// <param name="setting">Setting to be changed/added.</param>
 /// <param name="val">Value to change/add.</param>
 public static void SetValue(string setting, string val)
 {
     bool changed=false;
     System.Reflection.Assembly asm=System.Reflection.Assembly.GetEntryAssembly();
     System.IO.FileInfo fi=new System.IO.FileInfo(asm.Location+".config");
     System.Xml.XmlDataDocument doc= new System.Xml.XmlDataDocument();
     try
     {
         //Load the XML application configuration file
         doc.Load(fi.FullName);
         //Loops through the nodes to find the target node to change
         foreach (System.Xml.XmlNode node in doc["configuration"]["appSettings"])
         {
             if (node.Name=="add")
             {
                 //Set the key and value attributes
                 if (node.Attributes.GetNamedItem("key").Value==setting)
                 {
                     node.Attributes.GetNamedItem("value").Value=val;
                     //Flag the change as complete
                     changed=true;
                 }
             }
         }
         //If not changed yet then we assume it's a new key to be added
         if (!changed)
         {
             //create the new node and append it to the collection
             System.Xml.XmlNode node=doc["configuration"]["appSettings"];
             System.Xml.XmlElement elem=doc.CreateElement("add");
             System.Xml.XmlAttribute attrKey=doc.CreateAttribute("key");
             System.Xml.XmlAttribute attrVal=doc.CreateAttribute("value");
             elem.Attributes.SetNamedItem(attrKey).Value=setting;
             elem.Attributes.SetNamedItem(attrVal).Value=val;
             node.AppendChild(elem);
         }
         //Save the XML configuration file.
         doc.Save(fi.FullName);
     }
     catch
     {
         //There was an error loading or reading the config file...throw an error.
         throw new Exception("Unable to set the value.  Check that the configuration file exists and contains the appSettings element.");
     }
 }
示例#17
0
文件: MainWindow.cs 项目: mru00/vocab
        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);
        }
示例#18
0
 private void EncodeNodes(TreeViewItemCollection NColl, XmlElement myXML, XmlDataDocument myXMLobj)
 {
     foreach (TreeViewItem Itm in NColl)
      {
     XmlElement nx = myXMLobj.CreateElement("item");
     nx.SetAttribute("Text", Itm.Text);
     nx.SetAttribute("Image", Itm.Image);
     nx.SetAttribute("Link", Itm.Link);
     nx.SetAttribute("TargetFrame", Itm.TargetFrame);
     nx.SetAttribute("Open", Itm.Open.ToString());
     nx.SetAttribute("value", Itm.Value);
     nx.SetAttribute("Selector", Itm.Selector.ToString());
     nx.SetAttribute("Selected", Itm.Selected.ToString());
     nx.SetAttribute("OnClick", Itm.OnClick);
     nx.SetAttribute("LoadOnExpand", Itm.LoadOnExpand.ToString());
     myXML.AppendChild(nx);
     if (Itm.Items.Count > 0)
     {
        EncodeNodes(Itm.Items, nx, myXMLobj);
     }
      }
 }
 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);
 }
示例#20
0
		public void CreateElement1 ()
		{
			XmlDataDocument doc = new XmlDataDocument ();
			doc.DataSet.ReadXmlSchema ("Test/System.Xml/region.xsd");
			doc.Load ("Test/System.Xml/region.xml");
			
			XmlElement Element = doc.CreateElement ("prefix", "localname", "namespaceURI");
			Assert.AreEqual ("prefix", Element.Prefix, "test#01");
			Assert.AreEqual ("localname", Element.LocalName, "test#02");
			Assert.AreEqual ("namespaceURI", Element.NamespaceURI, "test#03");
			doc.ImportNode (Element, false);
			
			TextWriter text = new StringWriter ();
			doc.Save(text);

			string substring = string.Empty;
			string TextString = text.ToString ();

			substring = TextString.Substring (0, TextString.IndexOf("\n"));
			TextString = TextString.Substring (TextString.IndexOf("\n") + 1);

			substring = TextString.Substring (0, TextString.IndexOf("\n"));
			TextString = TextString.Substring (TextString.IndexOf("\n") + 1);
			Assert.IsTrue (substring.IndexOf ("<Root>") != -1, "test#05");

			substring = TextString.Substring (0, TextString.IndexOf("\n"));
			TextString = TextString.Substring (TextString.IndexOf("\n") + 1);
			Assert.IsTrue (substring.IndexOf ("  <Region>") != -1, "test#06");

			substring = TextString.Substring (0, TextString.IndexOf("\n"));
			TextString = TextString.Substring (TextString.IndexOf("\n") + 1);
			Assert.IsTrue (substring.IndexOf ("    <RegionID>1</RegionID>") != -1, "test#07");

			for (int i = 0; i < 26; i++) {
				substring = TextString.Substring (0, TextString.IndexOf("\n"));
				TextString = TextString.Substring (TextString.IndexOf("\n") + 1);
			}

			substring = TextString.Substring (0, TextString.Length);
			Assert.IsTrue (substring.IndexOf ("</Root>") != -1, "test#08");
		}
    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");

        }
    }