1. Scrierea unui document XML { XmlWriterSettings settings = new XmlWriterSettings(); [Link] = true; XmlWriter writer = [Link](@"c:\[Link]", settings); writer.
WriteStartDocument(); [Link]("File generated by RDP Manager"); [Link]("RDP"); [Link]("Machines"); [Link]("ID", "0"); [Link]("Type", "Sequencing"); [Link]("Name", [Link]("Name", [Link]("Name", [Link]("Name", [Link](); [Link]("Servers"); [Link]("ID", "1"); [Link]("Type", "Print"); [Link]("Name", [Link]("Name", [Link]("Name", [Link]("Name", [Link](); [Link](); [Link](); [Link](); } "ftwprn04"); "ftwprn06"); "phdprn04"); "phdprn06"); "ftwsqncws01"); "ftwsqncws02"); "ftwsqncws03"); "ftwsqncws04");
2. Citirea unui document XML
1. static void Main(string[] args) { TextWriter writeFile = new StreamWriter("c:\\[Link]"); XmlDocument doc = new XmlDocument(); XmlNode docNode = [Link]("1.0", "UTF-8", null); [Link](docNode); XmlNode productsNode = [Link]("products"); [Link](productsNode); XmlNode productNode = [Link]("product"); XmlAttribute productAttribute = [Link]("id");
[Link] = "01"; [Link](productAttribute); [Link](productNode); XmlNode nameNode = [Link]("Name"); [Link]([Link]("Java")); [Link](nameNode); XmlNode priceNode = [Link]("Price"); [Link]([Link]("Free")); [Link](priceNode); // Create and add another product node. productNode = [Link]("product"); productAttribute = [Link]("id"); [Link] = "02"; [Link](productAttribute); [Link](productNode); nameNode = [Link]("Name"); [Link]([Link]("C#")); [Link](nameNode); priceNode = [Link]("Price"); [Link]([Link]("Free")); [Link](priceNode); //[Link]([Link]); [Link](writeFile); } 2. { // Create the xml document containe XmlDocument doc = new XmlDocument();// Create the XML Declaration, and append it to XML document XmlDeclaration dec = [Link]("1.0", null, null); [Link](dec);// Create the root element XmlElement root = [Link]("Library"); [Link](root); // Create Books // Note that to set the text inside the element, // you use .InnerText instead of .Value (which will throw an exception). // You use SetAttribute to set attribute XmlElement book = [Link]("Book"); [Link]("BookType", "Hardcover"); XmlElement title = [Link]("Title"); [Link] = "Door Number Three"; XmlElement author = [Link]("Author"); [Link] = "O'Leary, Patrick"; [Link](title); [Link](author); [Link](book); book = [Link]("Book"); [Link]("BookType", "Paperback"); title = [Link]("Title"); [Link] = "Lord of Light"; author = [Link]("Author");
[Link] = "Zelanzy, Roger"; [Link](title); [Link](author); [Link](book); string xmlOutput = [Link]; }
3. { XmlWriterSettings wSettings = new XmlWriterSettings(); [Link] = true; MemoryStream ms = new MemoryStream(); XmlWriter xw = [Link](ms, wSettings);// Write Declaration [Link](); // Write the root node [Link]("Library"); // Write the books and the book elements [Link]("Book"); [Link]("BookType"); [Link]("Hardback"); [Link](); [Link]("Title"); [Link]("Door Number Three"); [Link](); [Link]("Author"); [Link]("O'Leary, Patrick"); [Link](); [Link](); // Write another book [Link]("Book"); [Link]("BookType"); [Link]("Paperback"); [Link](); [Link]("Title"); [Link]("Lord of Light"); [Link](); [Link]("Author"); [Link]("Zelanzy, Roger"); [Link](); [Link](); // Close the document [Link](); // Flush the write
[Link](); Byte[] buffer = new Byte[[Link]]; buffer = [Link](); string xmlOutput = [Link](buffer); }
static void Main(string[] args) { // Save the Starbuzz data SaveDataToAnXmlFile("[Link]"); // Read the XML data from [Link] XDocument starbuzzData = [Link]("[Link]"); // Query the data that was loaded QueryTheData(starbuzzData); // Don't quit until the user presses a key (just to make it easier to run in the // Visual Studio debugger -- since this is a learning exercise) [Link](); } static XDocument GetStarbuzzData() { /* * You can use an XDocument to create an XML file, and that includes XML * files you can read and write using DataContractSerializer. * * An XMLDocument object represents an XML document. It's part of the * [Link] namespace. * * Use XElement objects to create elements under the XML tree. */ XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Starbuzz Customer Loyalty Data"), new XElement("starbuzzData", new XAttribute("storeName", "Park Slope"), new XAttribute("location", "Brooklyn, NY"), new XElement("person", new XElement("personalInfo", new XElement("name", "Janet Venutian"), new XElement("zip", 11215)), new XElement("favoriteDrink", "Choco Macchiato"), new XElement("moneySpent", 255), new XElement("visits", 50)), new XElement("person", new XElement("personalInfo", new XElement("name", "Liz Nelson"), new XElement("zip", 11238)), new XElement("favoriteDrink", "Double Cappuccino"), new XElement("moneySpent", 150), new XElement("visits", 35)), new XElement("person",
new XElement("personalInfo", new XElement("name", "Matt Franks"), new XElement("zip", 11217)), new XElement("favoriteDrink", "Zesty Lemon Chai"), new XElement("moneySpent", 75), new XElement("visits", 15)), new XElement("person", new XElement("personalInfo", new XElement("name", "Joe Ng"), new XElement("zip", 11217)), new XElement("favoriteDrink", "Banana Split in a Cup"), new XElement("moneySpent", 60), new XElement("visits", 10)), new XElement("person", new XElement("personalInfo", new XElement("name", "Sarah Kalter"), new XElement("zip", 11215)), new XElement("favoriteDrink", "Boring Coffee"), new XElement("moneySpent", 110), new XElement("visits", 15)))); return doc; } static void SaveDataToAnXmlFile(string filename) { XDocument doc = GetStarbuzzData(); [Link](filename); } static void QueryTheData(XDocument doc) { // Do a simple query and print the results to the console var data = from item in [Link]("person") select new { drink = [Link]("favoriteDrink").Value, moneySpent = [Link]("moneySpent").Value, zipCode = [Link]("personalInfo").Element("zip").Value }; foreach (var p in data) [Link]([Link]()); // Do a more complex query and print the results to the console var zipcodeGroups = from item in [Link]("person") group [Link]("favoriteDrink").Value by [Link]("personalInfo").Element("zip").Value into zipcodeGroup select zipcodeGroup; foreach (var group in zipcodeGroups) [Link]("{0} favorite drinks in {1}", [Link]().Count(), [Link]); }