Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //11111111111111111111111111111111111111111
- /*using System;
- using System.Xml;
- namespace ReadingXML2
- {
- class Class1
- {
- static void Main(string[] args)
- {
- // Create a new file in C:\\ dir
- XmlTextWriter textWriter = new
- XmlTextWriter("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\1.xml", null);
- // Opens the document
- textWriter.WriteStartDocument();
- // Write comments
- textWriter.WriteComment("First Comment XmlTextWriter Sample Example");
- // Write first element
- textWriter.WriteStartElement("Student");
- textWriter.WriteStartElement("r", "RECORD", "urn:record");
- // Write next element
- textWriter.WriteStartElement("Name", "");
- textWriter.WriteString("Student");
- textWriter.WriteEndElement();
- // Write one more element
- textWriter.WriteStartElement("Address", "");
- textWriter.WriteString("Colony");
- textWriter.WriteEndElement();
- // WriteChars
- char[] ch = new char[3];
- ch[0] = 'a';
- ch[1] = 'r';
- ch[2] = 'c';
- textWriter.WriteStartElement("Char");
- textWriter.WriteChars(ch, 0, ch.Length);
- textWriter.WriteEndElement();
- // Ends the document.
- textWriter.WriteEndDocument();
- // close writer
- textWriter.Close();
- }
- }
- }*/
- //22222222222222222222222222222222222222222
- /*
- using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Xml.Linq;
- using System.Xml;
- using System.IO;
- using System;
- using System.Xml.XPath;
- class XMLtoACCESS
- {
- static void Main(string[] args)
- {
- XDocument myXML = XDocument.Load("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
- foreach (XElement el in myXML.Root.Elements("Product"))
- {
- if (el.Element("id").Value == "1")
- {
- Console.WriteLine(el);
- }
- }
- Console.ReadKey();
- }
- }*/
- //33333333333333333333333333333333333333333
- /*
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml.Linq;
- using System.Xml;
- using System.IO;
- using System.Threading;
- namespace XMLApplication1
- {
- class XMLtoACCESS
- {
- static void Main(string[] args)
- {
- System.Diagnostics.Process.Start("IExplore.exe", "file:///C:/Users/Yan/Desktop/BiBD-6lab/BIBD/BIBD4/Product.xml");
- Thread ThA = new Thread(
- () => {
- var f = new Form();
- var b = new WebBrowser() { Parent = f, Dock = DockStyle.Fill };
- b.Navigate(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- f.ShowDialog();
- Application.Run();
- }
- );
- ThA.SetApartmentState(ApartmentState.STA);
- ThA.Start();
- // ждем завершения потока
- ThA.Join();
- }
- }
- }
- */
- //44444444444444444444444444444444444444444
- /*
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml.Linq;
- using System.Xml;
- using System.IO;
- using System.Threading;
- namespace XMLApplication1
- {
- class XMLtoACCESS
- {
- static void Main(string[] args)
- {
- XDocument xDoc = XDocument.Load("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
- XNode xNewNode = new XElement("ProductAAA", new XElement("id", "7"),
- new XElement("name", "Утюг"),
- new XElement("price", "100"),
- new XElement("count", "25"));
- xDoc.Root.Add(xNewNode);
- xDoc.Save("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
- }
- }
- }
- */
- //55555555555555555555555555555555555555555
- /*using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml.Linq;
- using System.Xml;
- using System.IO;
- using System.Threading;
- */
- //Добавление атрибута
- /*class Program
- {
- static void Main(string[] args)
- {
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- XmlElement elmGarage = xmlDoc.CreateElement("Product1");
- elmGarage.SetAttribute("id", "9");
- elmGarage.SetAttribute("name", "Пылесос");
- elmGarage.SetAttribute("price", "350");
- elmGarage.SetAttribute("count", "5");
- xmlDoc.DocumentElement.AppendChild(elmGarage);
- xmlDoc.Save(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- }
- }*/
- //замена атрибута
- /*class Program
- {
- static void Main(string[] args)
- {
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- //Получаем все атрибуты элемента garage
- XmlAttributeCollection atrCol;
- atrCol = xmlDoc.DocumentElement["Product1"].Attributes;
- //изменяем значение атрибута id
- atrCol.GetNamedItem("id").InnerText = "15";
- xmlDoc.Save(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- }
- }*/
- //добавление нового атрибута
- /*class Program
- {
- static void Main(string[] args)
- {
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- //Получаем все атрибуты элемента garage
- XmlAttributeCollection atrCol = xmlDoc.
- DocumentElement["Product1"].Attributes;
- //Создаем новый атрибут
- XmlAttribute atrDate = xmlDoc.CreateAttribute("date");
- atrDate.Value = DateTime.Now.ToShortDateString();
- //Добавим в коллекцию новый атрибут
- atrCol.Append(atrDate);
- //Уберите комментарий возле нужного метода.
- //Вставить атрибут date после атрибута id
- atrCol.InsertBefore(atrCol["id"], atrDate);
- //Вставить атрибут date перед атрибутом id
- //atrCol.InsertAfter(atrCol["id"], atrDate);
- xmlDoc.Save(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- }
- }*/
- //удаление атрибута
- /*
- class Program
- {
- static void Main(string[] args)
- {
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- //Получаем все атрибуты элемента garage
- XmlAttributeCollection atrCol = xmlDoc.
- DocumentElement["Product1"].Attributes;
- atrCol.RemoveAt(4);
- xmlDoc.Save(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
- }
- }*/
- //66666666666666666666666666666666666666666
- /*using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Xml.Linq;
- using System.Xml;
- using System.IO;
- class XMLtoACCESS {
- static void Main(string[] args) {
- OleDbConnection con = new OleDbConnection();
- con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\1.mdb";
- OleDbDataAdapter sda = new OleDbDataAdapter();
- DataSet ds = new DataSet();
- XmlReader xmlr = XmlReader.Create("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\1.xml", new XmlReaderSettings());
- ds.ReadXml(xmlr);
- int n = ds.Tables[0].Columns.Count;
- con.Open();
- StringBuilder query = new StringBuilder();
- query.Append("CREATE TABLE ");
- query.Append(ds.Tables[0].TableName);
- query.Append(" ( ");
- for (int i = 0; i<n; i++)
- {
- query.Append("[");
- query.Append(ds.Tables[0].Columns[i].ColumnName);
- query.Append("] ");
- query.Append("varchar(30)");
- query.Append(", ");
- }
- query.Length -= 2;
- query.Append(");");
- OleDbCommand sqlQuery = new OleDbCommand(query.ToString(), con);
- sqlQuery.ExecuteNonQuery();
- for (int i = 0; i<ds.Tables[0].Rows.Count ; i++)
- {
- StringBuilder sql = new StringBuilder();
- sql.Append("INSERT INTO ");
- sql.Append(ds.Tables[0].TableName);
- sql.Append(" ");
- sql.Append("( ");
- for (int k = 0; k<n; k++)
- {
- sql.Append("[");
- sql.Append(ds.Tables[0].Columns[k].ColumnName);
- sql.Append("] ");
- sql.Append(", ");
- }
- sql.Length -= 2;
- sql.Append(")");
- sql.Append(" values ( ");
- for (int j = 0; j<n; j++)
- {
- sql.Append("'");
- sql.Append(ds.Tables[0].Rows[i].ItemArray[j]);
- sql.Append("'");
- sql.Append(" , ");
- }
- sql.Length -= 2;
- sql.Append(");");
- OleDbCommand sqlQuery1 = new OleDbCommand(sql.ToString(), con);
- sqlQuery1.ExecuteNonQuery();
- }
- con.Close();
- }
- }*/
- //77777777777777777777777777777777777777777
- /*using System;
- using System.Xml;
- using System.Data;
- using System.Data.OleDb;
- namespace ReadingXML2
- {
- class Class1
- {
- static void Main(string[] args)
- {
- // create a connection
- OleDbConnection con = new OleDbConnection();
- con.ConnectionString =
- "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\my.mdb";
- // create a data adapter
- OleDbDataAdapter da = new OleDbDataAdapter("Select * from tovary", con);
- // create a new dataset
- DataSet ds = new DataSet();
- // fill dataset
- da.Fill(ds, "tovary");
- // write dataset contents to an xml file by calling WriteXml method
- ds.WriteXml("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\OutputXML.xml");
- }
- }
- }*/
- //88888888888888888888888888888888888888888888888888888888888888888888888888
- //99999999999999999999999999999999999999999999999999999999999999999999999999
- /*using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Xml.Linq;
- using System.Xml;
- using System.IO;
- using System;
- using System.Xml.XPath;
- class XMLtoACCESS
- {
- static void Main(string[] args)
- {
- bool bl = false;
- XDocument myXML = XDocument.Load("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
- foreach (XElement el in myXML.Root.Elements("Product"))
- {
- if (el.Element("id").Value == "1")
- {
- //el.remove;
- el.SetElementValue("price", "200");
- el.SetElementValue("count", "1000");
- Console.WriteLine(el);
- bl = true;
- }
- }
- if (bl) myXML.Save("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement