Submit Search
Upload
C# Tutorial MSM_Murach chapter-22-slides
•
Download as PPT, PDF
•
2 likes
•
310 views
S
Sami Mut
Follow
Murach chapter- 22 How to work with XML files slides
Read less
Read more
Technology
Slideshow view
Report
Share
Slideshow view
Report
Share
1 of 26
Download now
Recommended
C# Tutorial MSM_Murach chapter-14-slides
C# Tutorial MSM_Murach chapter-14-slides
Sami Mut
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slides
Sami Mut
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
Sami Mut
C# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slides
Sami Mut
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slides
Sami Mut
C# Tutorial MSM_Murach chapter-21-slides
C# Tutorial MSM_Murach chapter-21-slides
Sami Mut
C# Tutorial MSM_Murach chapter-05-slides
C# Tutorial MSM_Murach chapter-05-slides
Sami Mut
C# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slides
Sami Mut
Recommended
C# Tutorial MSM_Murach chapter-14-slides
C# Tutorial MSM_Murach chapter-14-slides
Sami Mut
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slides
Sami Mut
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
Sami Mut
C# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slides
Sami Mut
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slides
Sami Mut
C# Tutorial MSM_Murach chapter-21-slides
C# Tutorial MSM_Murach chapter-21-slides
Sami Mut
C# Tutorial MSM_Murach chapter-05-slides
C# Tutorial MSM_Murach chapter-05-slides
Sami Mut
C# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slides
Sami Mut
C# Tutorial MSM_Murach chapter-24-slides
C# Tutorial MSM_Murach chapter-24-slides
Sami Mut
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
Sami Mut
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
Sami Mut
C# Tutorial MSM_Murach chapter-12-slides
C# Tutorial MSM_Murach chapter-12-slides
Sami Mut
C# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slides
Sami Mut
Intake 38 8
Intake 38 8
Mahmoud Ouf
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business Rules
Emiel Paasschens
Vb6.0 intro
Vb6.0 intro
JOSEPHINEA6
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
francopw
Visual programming
Visual programming
Dr. C.V. Suresh Babu
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
simran153
Vb introduction.
Vb introduction.
sagaroceanic11
visual basic programming
visual basic programming
sowndaryadharmaraj
Visual Programming
Visual Programming
Bagzzz
Vb tutorial
Vb tutorial
Saikarthik103212
Visual Basic Programming
Visual Basic Programming
Osama Yaseen
Visual basic 6.0
Visual basic 6.0
sanket1996
Creating a quiz using visual basic 6
Creating a quiz using visual basic 6
Ella Marie Wico
Chapter03 Ppt
Chapter03 Ppt
Osama Yaseen
C# Tutorial MSM_Murach chapter-25-slides
C# Tutorial MSM_Murach chapter-25-slides
Sami Mut
C# Tutorial MSM_Murach chapter-19-slides
C# Tutorial MSM_Murach chapter-19-slides
Sami Mut
C# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slides
Sami Mut
More Related Content
What's hot
C# Tutorial MSM_Murach chapter-24-slides
C# Tutorial MSM_Murach chapter-24-slides
Sami Mut
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
Sami Mut
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
Sami Mut
C# Tutorial MSM_Murach chapter-12-slides
C# Tutorial MSM_Murach chapter-12-slides
Sami Mut
C# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slides
Sami Mut
Intake 38 8
Intake 38 8
Mahmoud Ouf
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business Rules
Emiel Paasschens
Vb6.0 intro
Vb6.0 intro
JOSEPHINEA6
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
francopw
Visual programming
Visual programming
Dr. C.V. Suresh Babu
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
simran153
Vb introduction.
Vb introduction.
sagaroceanic11
visual basic programming
visual basic programming
sowndaryadharmaraj
Visual Programming
Visual Programming
Bagzzz
Vb tutorial
Vb tutorial
Saikarthik103212
Visual Basic Programming
Visual Basic Programming
Osama Yaseen
Visual basic 6.0
Visual basic 6.0
sanket1996
Creating a quiz using visual basic 6
Creating a quiz using visual basic 6
Ella Marie Wico
Chapter03 Ppt
Chapter03 Ppt
Osama Yaseen
What's hot
(19)
C# Tutorial MSM_Murach chapter-24-slides
C# Tutorial MSM_Murach chapter-24-slides
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-12-slides
C# Tutorial MSM_Murach chapter-12-slides
C# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slides
Intake 38 8
Intake 38 8
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business Rules
Vb6.0 intro
Vb6.0 intro
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
Visual programming
Visual programming
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
Vb introduction.
Vb introduction.
visual basic programming
visual basic programming
Visual Programming
Visual Programming
Vb tutorial
Vb tutorial
Visual Basic Programming
Visual Basic Programming
Visual basic 6.0
Visual basic 6.0
Creating a quiz using visual basic 6
Creating a quiz using visual basic 6
Chapter03 Ppt
Chapter03 Ppt
Viewers also liked
C# Tutorial MSM_Murach chapter-25-slides
C# Tutorial MSM_Murach chapter-25-slides
Sami Mut
C# Tutorial MSM_Murach chapter-19-slides
C# Tutorial MSM_Murach chapter-19-slides
Sami Mut
C# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slides
Sami Mut
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
Sami Mut
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
Getting Started With SlideShare
Getting Started With SlideShare
SlideShare
Viewers also liked
(6)
C# Tutorial MSM_Murach chapter-25-slides
C# Tutorial MSM_Murach chapter-25-slides
C# Tutorial MSM_Murach chapter-19-slides
C# Tutorial MSM_Murach chapter-19-slides
C# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
Getting Started With SlideShare
Getting Started With SlideShare
Similar to C# Tutorial MSM_Murach chapter-22-slides
Document object model
Document object model
Amit kumar
Webcomponents v2
Webcomponents v2
Dmitry Bakaleinik
Webcomponents TLV October 2014
Webcomponents TLV October 2014
Dmitry Bakaleinik
Web components
Web components
Mohd Saeed
HTML literals, the JSX of the platform
HTML literals, the JSX of the platform
Kenneth Rohde Christiansen
XML Introduction
XML Introduction
Marco Bresciani
ASP.NET MVC3 RAD
ASP.NET MVC3 RAD
Mădălin Ștefîrcă
HTML practical file
HTML practical file
Kuldeep Sharma
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptx
karthiksmart21
Xml
Xml
sudhakar mandal
Web engineering UNIT IV as per RGPV syllabus
Web engineering UNIT IV as per RGPV syllabus
NANDINI SHARMA
MCA-202-W4-L1.pptx
MCA-202-W4-L1.pptx
manju451965
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
Dr.Florence Dayana
Xml11
Xml11
Sudharsan S
Xml Presentation-1
Xml Presentation-1
Sudharsan S
Unit 5 xml (1)
Unit 5 xml (1)
manochitra10
Xml
Xml
Santosh Pandey
Presentation html
Presentation html
Billy Tierra
Dom structure
Dom structure
baabtra.com - No. 1 supplier of quality freshers
Dom structure
Dom structure
baabtra.com - No. 1 supplier of quality freshers
Similar to C# Tutorial MSM_Murach chapter-22-slides
(20)
Document object model
Document object model
Webcomponents v2
Webcomponents v2
Webcomponents TLV October 2014
Webcomponents TLV October 2014
Web components
Web components
HTML literals, the JSX of the platform
HTML literals, the JSX of the platform
XML Introduction
XML Introduction
ASP.NET MVC3 RAD
ASP.NET MVC3 RAD
HTML practical file
HTML practical file
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptx
Xml
Xml
Web engineering UNIT IV as per RGPV syllabus
Web engineering UNIT IV as per RGPV syllabus
MCA-202-W4-L1.pptx
MCA-202-W4-L1.pptx
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
Xml11
Xml11
Xml Presentation-1
Xml Presentation-1
Unit 5 xml (1)
Unit 5 xml (1)
Xml
Xml
Presentation html
Presentation html
Dom structure
Dom structure
Dom structure
Dom structure
More from Sami Mut
C# Tutorial MSM_Murach chapter-13-slides
C# Tutorial MSM_Murach chapter-13-slides
Sami Mut
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slides
Sami Mut
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slides
Sami Mut
C# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slides
Sami Mut
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slides
Sami Mut
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slides
Sami Mut
C# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slides
Sami Mut
MSM_Time
MSM_Time
Sami Mut
chapter 5 Java at rupp cambodia
chapter 5 Java at rupp cambodia
Sami Mut
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
Sami Mut
chapter 3 Java at rupp cambodia
chapter 3 Java at rupp cambodia
Sami Mut
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
Sami Mut
chapter 1 Java at rupp cambodia
chapter 1 Java at rupp cambodia
Sami Mut
More from Sami Mut
(13)
C# Tutorial MSM_Murach chapter-13-slides
C# Tutorial MSM_Murach chapter-13-slides
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slides
MSM_Time
MSM_Time
chapter 5 Java at rupp cambodia
chapter 5 Java at rupp cambodia
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
chapter 3 Java at rupp cambodia
chapter 3 Java at rupp cambodia
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
chapter 1 Java at rupp cambodia
chapter 1 Java at rupp cambodia
Recently uploaded
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
naman860154
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Pixlogix Infotech
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April Automation LPDG
MarianaLemus7
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
Scott Keck-Warren
The transition to renewables in India.pdf
The transition to renewables in India.pdf
Competition Advisory Services (India) LLP
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Fwdays
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
2toLead Limited
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
ThousandEyes
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Scott Keck-Warren
Key Features Of Token Development (1).pptx
Key Features Of Token Development (1).pptx
LBM Solutions
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
null - The Open Security Community
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
Dubai Multi Commodity Centre
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
Neo4j
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
Softradix Technologies
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
Kalema Edgar
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Sinan KOZAK
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
Fwdays
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
BookNet Canada
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
comworks
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Memoori
Recently uploaded
(20)
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April Automation LPDG
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
The transition to renewables in India.pdf
The transition to renewables in India.pdf
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Key Features Of Token Development (1).pptx
Key Features Of Token Development (1).pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
C# Tutorial MSM_Murach chapter-22-slides
1.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 1 Chapter 22 How to work with XML files
2.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 2 Objectives Applied 1. Use the XmlWriter class to write an XML document. 2. Use the XmlReader class to read an XML document. 3. Use Visual Studio’s XML Editor to create and edit an XML document in a project. Knowledge 1. Identify the following in an XML document: XML declarations, start tags, end tags, root elements, parent elements, child elements, attributes, element content, and comments.
3.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 3 Data for three products Code Description Price A3CS Murach’s ASP.NET 3.5 with C# 2008 54.50 JSE6 Murach’s Java SE 6 52.50 CS08 Murach’s C# 2008 54.50
4.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 4 An XML document that contains the product data <?xml version="1.0" encoding="utf-8" ?> <!--Product data--> <Products> <Product Code="A3CS"> <Description>Murach's ASP.NET 3.5 with C# 2008 </Description> <Price>54.50</Price> </Product> <Product Code="JSE6"> <Description>Murach's Java SE 6 </Description> <Price>52.50</Price> </Product> <Product Code="CS08"> <Description>Murach's C# 2008 </Description> <Price>54.50</Price> </Product> </Products>
5.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 5 An XML document <?xml version="1.0" encoding="utf-8" ?> <!--Product data--> <Products> <Product Code="CS08"> <Description>Murach's C# 2008</Description> <Price>54.50</Price> </Product> </Products> Product element Description element Price element
6.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 6 Tags, XML declarations, and comments • Each XML tag begins with < and ends with >. • The first line in an XML document is an XML declaration that indicates which version of the XML standard is being used for the document. • In addition, the declaration usually identifies the standard character set that’s being used. For documents in English- speaking countries, UTF-8 is the character set that’s commonly used. • You can use the <!-- and --> tags to include comments in an XML document.
7.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 7 Elements • An element is a unit of XML data that begins with a start tag and ends with an end tag. • The start tag provides the name of the element and contains any attributes assigned to the element. • The end tag repeats the name, prefixed with a slash (/). • The text between an element’s start and end tags is called the element’s content. • You can use any name you want for an XML element. • Elements can contain other elements. An element that’s contained within another is known as a child element. The element that contains a child element is known as the child’s parent element. • Child elements can repeat within a parent element. • The highest-level parent element in an XML document is known as the root element.
8.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 8 An XML document with a Code attribute <?xml version="1.0" encoding="utf-8" ?> <!--Product data--> <Products> <Product Code="CS08"> <Description>Murach's C# 2008</Description> <Price>54.50</Price> </Product> </Products> Attributes • You can include one or more attributes in the start tag for an element. • An attribute consists of an attribute name, an equal sign, and a string value in quotes. • If an element has more than one attribute, the order in which the attributes appear doesn’t matter, but the attributes must be separated by one or more spaces.
9.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 9 When to use attributes instead of child elements • When you design an XML document, you can use either a child element or an attribute to represent a data item for an element. The choice of one over the other is often a matter of preference. • Two advantages of attributes are that they can appear in any order and they are more concise because they do not require end tags. • Two advantages of child elements are that they are easier for people to read and they are more convenient for long string values.
10.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 10 An XML document in the XML Editor
11.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 11 How to add a new XML file to a project • Choose the ProjectAdd New Item command. In the Add New Item dialog box, select the XML File template; type a name for the XML file in the Name text box; and click Open. • This adds an XML file to your project, adds the XML declaration for the document, and opens the document in the XML Editor. How to open an existing XML file • To open an existing XML file that’s stored in the project, double- click on the file. • To open an existing XML file without adding the file to your project, use the FileOpen command.
12.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 12 How to edit an XML file • When you type a start tag, the XML Editor automatically adds an end tag for the element and positions the insertion point between the start and end tags so you can type the element’s content. • When you type an attribute, the XML Editor automatically adds a pair of quotation marks and positions the insertion point between them so you can type the attribute value.
13.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 13 Common methods of the XmlWriter class • Create(path) • Create(path, settings) • WriteStartDocument() • WriteComment(comment) • WriteStartElement(elementName) • WriteAttributeString(attributeName, value) • WriteEndElement() • WriteElementString(elementName, content) • Close() Common properties of the XmlWriterSettings class • Indent • IndentChars
14.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 14 Code that writes an XML document // create the path variable string path = @"C:C# 2010FilesProducts.xml"; // create the XmlWriterSettings object XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" "); // create the XmlWriter object XmlWriter xmlOut = XmlWriter.Create(path, settings); // write the start of the document xmlOut.WriteStartDocument(); xmlOut.WriteStartElement("Products");
15.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 15 Code that writes an XML document (cont.) // write each Product object to the xml file foreach (Product product in products) { xmlOut.WriteStartElement("Product"); xmlOut.WriteAttributeString("Code", product.Code); xmlOut.WriteElementString("Description", product.Description); xmlOut.WriteElementString("Price", Convert.ToString(product.Price)); xmlOut.WriteEndElement(); } // write the end tag for the root element xmlOut.WriteEndElement(); // close the XmlWriter object xmlOut.Close();
16.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 16 Common indexer of the XmlReader class • [name] Common properties of the XmlReader class • NodeType • Name • Value • EOF
17.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 17 Common methods of XmlReader class • Create(path) • Create(path, settings) • Read() • ReadStartElement(name) • ReadEndElement() • ReadToDescendant(name) • ReadToNextSibling(name) • ReadElementContentAsString() • ReadElementContentAsDecimal() • Close() Common properties of XmlReaderSettings class • IgnoreWhitespace • IgnoreComments
18.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 18 An XML document <?xml version="1.0"> <!--Product data--> <Products> <Product Code="CS08"> <Description>Murach's C# 2008 </Description> <Price>54.50</Price> </Product> </Products>
19.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 19 The XML nodes in the products document NodeType Name Other properties XmlDeclaration xml Comment Value = “Product data” Element Products Element Product [“Code”] = “CS08” Element Description Text Value = “Murach’s C# 2008” EndElement Description Element Price Text Value = “54.50” EndElement Price EndElement Product EndElement Products
20.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 20 Code that reads an XML document // create the list List<Product> products = new List<Product>(); // create the path variable string path = @"C:C# 2010FilesProducts.xml"; // create the XmlReaderSettings object XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true; // create the XmlReader object XmlReader xmlIn = XmlReader.Create(path, settings);
21.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 21 Code that reads an XML document (cont.) // read past all nodes to the first Product node if {xmlIn.ReadToDescendant("Product")); { // create one Product object for each Product node do { Product product = new Product(); product.Code = xmlIn["Code"]; xmlIn.ReadStartElement("Product"); product.Description = xmlIn.ReadElementContentAsString(); product.Price = xmlIn.ReadElementContentAsDecimal(); products.Add(product); } while(xmlIn.ReadToNextSibling("Product")); } // close the XmlReader object xmlIn.Close();
22.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 22 A class that works with an XML document using System; using System.Xml; using System.Collections.Generic; namespace ProductMaintenance { public class ProductDB { private const string path = @"C:C# 2010FilesProducts.xml"; public static List<Product> GetProducts() { // create the list List<Product> products = new List<Product>(); // create the XmlReaderSettings object XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true;
23.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 23 A class that works with an XML document (cont.) // create the XmlReader object XmlReader xmlIn = XmlReader.Create( path, settings); // read past all nodes to first Product node if {xmlIn.ReadToDescendant("Product")); { // create object for each Product node do { Product product = new Product(); product.Code = xmlIn["Code"]; xmlIn.ReadStartElement("Product"); product.Description = xmlIn.ReadElementContentAsString(); product.Price = xmlIn.ReadElementContentAsDecimal(); products.Add(product); } while(xmlIn.ReadToNextSibling("Product")); }
24.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 24 A class that works with an XML document (cont.) // close the XmlReader object xmlIn.Close(); return products; } public static void SaveProducts( List<Product> products) { // create the XmlWriterSettings object XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" "); // create the XmlWriter object XmlWriter xmlOut = XmlWriter.Create(path, settings);
25.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 25 A class that works with an XML document (cont.) // write the start of the document xmlOut.WriteStartDocument(); xmlOut.WriteStartElement("Products"); // write each Product object to the xml file foreach (Product product in products) { xmlOut.WriteStartElement("Product"); xmlOut.WriteAttributeString("Code", product.Code); xmlOut.WriteElementString("Description", product.Description); xmlOut.WriteElementString("Price", Convert.ToString(product.Price)); xmlOut.WriteEndElement(); }
26.
Murach’s C# 2010,
C22 © 2010, Mike Murach & Associates, Inc. Slide 26 A class that works with an XML document (cont.) // write the end tag for the root element xmlOut.WriteEndElement(); // close the XmlWriter object xmlOut.Close(); } } }
Download now