SlideShare a Scribd company logo
Developing Database Applications Using ADO.NET and XML
Objectives


                In this session, you will learn to:
                   Read, write, validate, and modify XML data by using the XML
                   reader and writer classes




     Ver. 1.0                      Session 11                           Slide 1 of 24
Developing Database Applications Using ADO.NET and XML
Processing XML Data


                •   You can process XML data in your .NET applications using
                    the System.Xml namespace.
                •   The System.Xml namespace contains many classes to
                    write and read XML documents.
                •   Using these classes, you can create an XML document,
                    process an XML document, validate an XML document, and
                    so on.




     Ver. 1.0                       Session 11                       Slide 2 of 24
Developing Database Applications Using ADO.NET and XML
Writing XML Data


                • The XmlWriter class in the System.Xml namespace
                  provides non-cached, forward-only, and write-only access to
                  XML data.
                • XmlWriter objects are created using the Create()
                  method.
                • You can pass an object of XmlWriterSettings class to
                  the Create()method in order to specify the settings or
                  properties, which you want to enable on the XmlWriter
                  object. If an XmlWriterSettings is not passed as a
                  parameter, the default settings are applied.
                • The following line of code snippet creates an XmlWriter
                  object that creates an XML file called myXmlFile.xml:
                    XmlWriter writer =
                    XmlWriter.Create(“myXmlFile.xml”,settings);


     Ver. 1.0                      Session 11                         Slide 3 of 24
Developing Database Applications Using ADO.NET and XML
Just a minute


                Fill in the blanks:
                    The __________ namespace in .NET contains XML classes.




                Answer:
                    System.Xml



     Ver. 1.0                         Session 11                     Slide 4 of 24
Developing Database Applications Using ADO.NET and XML
Writing XML Data (Contd.)


                    An XML file includes elements, attributes and comments.
                       Elements
                       Attributes
                       Comments
                •   All these can be created by using various methods of
                    XmlWriter class.




     Ver. 1.0                        Session 11                            Slide 5 of 24
Developing Database Applications Using ADO.NET and XML
Writing XML Data (Contd.)


                Elements can be created in two ways:
                 By calling the       The WriteElementString()method takes
                  WriteElementString() two value of the element. of the element and
                                       the
                                           parameters, the name

                  method               writer.WriteElementString(“Name”,
                                               “Peter”);
                                               Here, writer is an object of XmlWriter,
                                               Name is the name of the element and Peter is
                                               the value of the element.
                 By calling the               The WriteStartElement() method takes
                                               the name of the element as a parameter. The
                  WriteStartElement()          WriteString() method to specify a value for
                  method                       this element. The WriteEndElement()
                                               method to end the element tag.
                                               writer.WriteStartElement(“Name”);
                                               writer.WriteString(“Peter”);
                                               writer.WriteEndElement();




     Ver. 1.0                     Session 11                                   Slide 6 of 24
Developing Database Applications Using ADO.NET and XML
Just a minute


                •   What is the code snippet to store the value of an integer
                    type variable named Age into an XML file?




                    Answer:
                      //writer is an object of XmlWriter
                       writer.WriteElementString(“Age”,XmlConvert.To
                       String(Age));

     Ver. 1.0                        Session 11                           Slide 7 of 24
Developing Database Applications Using ADO.NET and XML
Writing XML Data (Contd.)


                Attributes can be created in two ways:
                  By calling the              This method takes the name of the
                                               attribute and the value of the attribute as
                   WriteAttributeString()      parameters.
                   method                      //writer is an object of
                                               //XmlWriter

                                               writer.WriteAttributeString(“O
                                               rderID”,“O001”);
                                               In the preceding code snippet, an
                                               attribute OrderID with the value
                  By calling the              O001 is created.
                   WriteStartAttribute()       This method takes the name of the
                   method                      attribute as a parameter. The
                                               WriteString() method writes the
                                               value of the attribute. The
                                               WriteEndAttribute() method ends
                                               the attribute tag.
                                               writer.WriteStartAttribute("Or
                                               derID");
                                               writer.WriteString("O001");
     Ver. 1.0                    Session 11    writer.WriteEndAttribute();8 of 24
                                                                              Slide
Developing Database Applications Using ADO.NET and XML
Writing XML Data (Contd.)


                Comments can be created in the following way:
                 By calling the             This method takes a string as a
                                             parameter. This string is written as a
                  WriteComment()             comment in the XML file. The following
                  method                     code snippet writes a comment into an
                                             XML file:
                                              //writer is an object of XmlWriter
                                             writer.WriteComment(“This XML
                                             file stores product details”);
                                             The text This XML file stores product
                                             details will be written within the <!--
                                             and
                                             --> tags in the XML file.




     Ver. 1.0                   Session 11                                 Slide 9 of 24
Developing Database Applications Using ADO.NET and XML
Just a minute


                Fill in the blanks:
                  The __________ method of the XmlWriter class is used to
                   write comments into an XML file.




                Answer:
                    WriteComment()



     Ver. 1.0                         Session 11                    Slide 10 of 24
Developing Database Applications Using ADO.NET and XML
Writing XML Data (Contd.)


                An XML file can be created in the following ways:
                  Using XmlWriter
                  Using XmlTextWriter
                  Saving a Dataset as XML data




     Ver. 1.0                    Session 11                         Slide 11 of 24
Developing Database Applications Using ADO.NET and XML
Just a minute


                Fill in the blanks:
                  The _______ option of XmlWriteMode write the contents of
                   the dataset as XML data with the dataset structure as an inline
                   schema.




                Answer:
                    WriteSchema



     Ver. 1.0                         Session 11                          Slide 12 of 24
Developing Database Applications Using ADO.NET and XML
Reading XML Data


               • The XmlReader class in the System.Xml namespace
                 provides non-cached, forward-only, and read-only access to
                 XML data.
               • XmlReader objects are created using the Create()
                 method.
               • You can pass an object of XmlReaderSettings class to
                 the Create()method in order to specify the settings or
                 properties, which you want to enable on the XmlReader
                 object. If an XmlReaderSettings is not passed as a
                 parameter, the default settings are applied.
               • The following code snippet creates an XmlReader object,
                 which reads an XML file called books.xml:
                  XmlReader reader = null;
                  reader = XmlReader.Create("C:books.xml",
                  settings);
    Ver. 1.0                      Session 11                        Slide 13 of 24
Developing Database Applications Using ADO.NET and XML
Reading XML Data (Contd.)


                An XML file can be read by using the following classes:
                   XmlReader
                   XmlTextReader




     Ver. 1.0                    Session 11                         Slide 14 of 24
Developing Database Applications Using ADO.NET and XML
Just a minute


                Fill in the blanks:
                  The _______ method of the XmlTextReader class reads the
                   content of an element or text node in a string.




                Answer:
                    ReadString()



     Ver. 1.0                         Session 11                  Slide 15 of 24
Developing Database Applications Using ADO.NET and XML
Validating XML Data


                An XML file can be validated against a schema using the
                following two classes:
                   XmlReader
                   XmlValidatingReader




     Ver. 1.0                   Session 11                         Slide 16 of 24
Developing Database Applications Using ADO.NET and XML
Validating XML Data (Contd.)


                •   The following code snippet validates an XML file against a
                    schema using XmlReader:
                    XmlSchemaSet schemaSet = new            Create the XmlSchemaSet
                    XmlSchemaSet();                         class.
                    schemaSet.Add("urn:product              Add the schema to the
                                                            collection.
                    -schema",C:products.xsd");
                                                            Set the validation settings.
                    XmlReaderSettings settings =
                    new XmlReaderSettings();
                    settings.ValidationType =
                    ValidationType.Schema;
                    settings.Schemas = schemaSet;           Associate the
                                                            ValidationEventHandler
                    settings.ValidationEventHandler
                                                            to detect validation errors.
                    += new alidationEventHandler
                    (ValidationCallBack);


     Ver. 1.0                        Session 11                              Slide 17 of 24
Developing Database Applications Using ADO.NET and XML
Validating XML Data (Contd.)




                XmlReader reader =               Create the XmlReader
                XmlReader.Create                 object.
                ("C:products.xml“,settings);
                while (reader.Read());
                                                 Parse the file
                Console.ReadLine();




     Ver. 1.0                Session 11                           Slide 18 of 24
Developing Database Applications Using ADO.NET and XML
Validating XML Data (Contd.)


                •   The following code snippet validates an XML file against a
                    schema using XmlValidatingReader:
                     XmlTextReader reader = new            Read the products.xml file.
                     XmlTextReader
                     ("C:products.xml");
                     XmlValidatingReader                   Add validation support the
                     validatingReader = new                XmlTextReader object.
                     XmlValidatingReader(reader);
                     validatingReader.ValidationType       Set validation type as Schema.
                     = ValidationType.Schema;




     Ver. 1.0                        Session 11                              Slide 19 of 24
Developing Database Applications Using ADO.NET and XML
Modifying XML Data Using DiffGrams


                DiffGram:
                   Is an XML format that identifies current and original versions of
                   data elements.
                   Preserves information about changes to the data in the dataset
                   so that you can choose whether to accept or reject the
                   changes when you read the XML data back to the dataset.
                   Is created in the following way:
                  ds.WriteXml("C:Employee             DataSet object
                  Details.xml",                         Name of the XML file
                  XmlWriteMode.DiffGram);




     Ver. 1.0                      Session 11                              Slide 20 of 24
Developing Database Applications Using ADO.NET and XML
Demo: Manipulating XML Data


               Problem Statement:
                  Tebisco has its central office in New York and several branch
                  offices across the United States. Tebisco collaborates with
                  various recruitment agencies for hiring purposes. Currently,
                  only the HR management team at the central office is provided
                  with the details of the recruitment agencies. In addition, only
                  the central office interacts with these recruitment agencies. If
                  the branch offices need to interact with the recruitment
                  agencies, they first have to interact with the central office.
                  However, this process is taking time and, therefore, it has been
                  decided to send the details of the recruitment agencies to the
                  branch offices in a suitable format.




    Ver. 1.0                     Session 11                              Slide 21 of 24
Developing Database Applications Using ADO.NET and XML
Demo: Manipulating XML Data (Contd.)


                You are a developer in Tebisco. You have been asked to
                create an application that will retrieve the records stored in the
                RecruitmentAgencies table into a dataset and perform the
                following tasks:
                 1. Save the dataset as XML.
                 2. Save the dataset as a DiffGram.




     Ver. 1.0                   Session 11                                Slide 22 of 24
Developing Database Applications Using ADO.NET and XML
Summary


               In this session, you learned that:
                 System.Xml namespace contains XML classes. This
                  namespace contains many classes to read and write XML
                  documents.
                 The XmlWriter class in the System.Xml namespace
                  provides non-cached, forward-only, and write-only access to
                  XML data. This class can be used to write either a stream of
                  data or a text data.
                 The XmlReader class in the System.Xml namespace
                  provides non-cached, forward-only, and read-only access to
                  XML data. If the XML file is not well formed, the XmlReader
                  raises an XmlException.




    Ver. 1.0                      Session 11                            Slide 23 of 24
Developing Database Applications Using ADO.NET and XML
Summary (Contd.)


                 An XML document can be validated against a schema by using
                 the following two classes:
                    XmlReader
                    XmlValidatingReader
                A DiffGram is an XML format that identifies current and original
                 versions of data elements.




    Ver. 1.0                     Session 11                             Slide 24 of 24

More Related Content

PDF
C# Advanced L03-XML+LINQ to XML
PPT
Chapter 7 - Defining Your Own Classes - Part II
PPT
Chapter 4 - Defining Your Own Classes - Part I
PPTX
PPS
04 sm3 xml_xp_08
PDF
Tool Development 05 - XML Schema, INI, JSON, YAML
PDF
CSharp Advanced L05-Attributes+Reflection
PDF
Tool Development 04 - XML
C# Advanced L03-XML+LINQ to XML
Chapter 7 - Defining Your Own Classes - Part II
Chapter 4 - Defining Your Own Classes - Part I
04 sm3 xml_xp_08
Tool Development 05 - XML Schema, INI, JSON, YAML
CSharp Advanced L05-Attributes+Reflection
Tool Development 04 - XML

What's hot (20)

PPTX
12. session 12 java script objects
PDF
C# Advanced L07-Design Patterns
PPS
Introduction to class in java
PPTX
Class introduction in java
PPT
Serialization/deserialization
PDF
Java ppt Gandhi Ravi (gandhiri@gmail.com)
PPTX
11. session 11 functions and objects
PDF
S313937 cdi dochez
PPTX
Serialization in java
PPTX
java API for XML DOM
PPTX
The xml
PDF
Java Serialization
PPT
UML and You
PPT
JAVA CONCEPTS
PDF
Intro to iOS Development • Made by Many
PPTX
Cordova training : Day 4 - Advanced Javascript
PPTX
Session 09 - OOPS
DOC
Serialization in .NET
PDF
Spring 3: What's New
12. session 12 java script objects
C# Advanced L07-Design Patterns
Introduction to class in java
Class introduction in java
Serialization/deserialization
Java ppt Gandhi Ravi (gandhiri@gmail.com)
11. session 11 functions and objects
S313937 cdi dochez
Serialization in java
java API for XML DOM
The xml
Java Serialization
UML and You
JAVA CONCEPTS
Intro to iOS Development • Made by Many
Cordova training : Day 4 - Advanced Javascript
Session 09 - OOPS
Serialization in .NET
Spring 3: What's New
Ad

Similar to Ado.net session11 (20)

PPTX
Xml writers
PPS
Ado.net session13
PPTX
Working with XML and JSON Serializing
PDF
JavaScript - Chapter 12 - Document Object Model
PDF
Advanced Web Programming Chapter 12
PPT
Session 4
PDF
INTRODUCTION TO CLIENT SIDE PROGRAMMING
PPTX
06 xml processing-in-.net
PPTX
PPTX
Ian 2014.10.24 weekly report
PPS
04 sm3 xml_xp_07
PPT
It seminar-xml serialization
PPT
It seminar-xml serialization
PPS
02 sm3 xml_xp_03
PPS
Ado.net session14
PDF
3. lecture 8 javascriptno.pdssssssssssssf
PPT
Entity framework1
PPT
Understanding XML DOM
PPTX
Reflection in C#
PPT
Attributes & .NET components
Xml writers
Ado.net session13
Working with XML and JSON Serializing
JavaScript - Chapter 12 - Document Object Model
Advanced Web Programming Chapter 12
Session 4
INTRODUCTION TO CLIENT SIDE PROGRAMMING
06 xml processing-in-.net
Ian 2014.10.24 weekly report
04 sm3 xml_xp_07
It seminar-xml serialization
It seminar-xml serialization
02 sm3 xml_xp_03
Ado.net session14
3. lecture 8 javascriptno.pdssssssssssssf
Entity framework1
Understanding XML DOM
Reflection in C#
Attributes & .NET components
Ad

More from Niit Care (20)

PPS
Ajs 1 b
PPS
Ajs 4 b
PPS
Ajs 4 a
PPS
Ajs 4 c
PPS
Ajs 3 b
PPS
Ajs 3 a
PPS
Ajs 3 c
PPS
Ajs 2 b
PPS
Ajs 2 a
PPS
Ajs 2 c
PPS
Ajs 1 a
PPS
Ajs 1 c
PPS
Dacj 4 2-c
PPS
Dacj 4 2-b
PPS
Dacj 4 2-a
PPS
Dacj 4 1-c
PPS
Dacj 4 1-b
PPS
Dacj 4 1-a
PPS
Dacj 1-2 b
PPS
Dacj 1-3 c
Ajs 1 b
Ajs 4 b
Ajs 4 a
Ajs 4 c
Ajs 3 b
Ajs 3 a
Ajs 3 c
Ajs 2 b
Ajs 2 a
Ajs 2 c
Ajs 1 a
Ajs 1 c
Dacj 4 2-c
Dacj 4 2-b
Dacj 4 2-a
Dacj 4 1-c
Dacj 4 1-b
Dacj 4 1-a
Dacj 1-2 b
Dacj 1-3 c

Recently uploaded (20)

PDF
Architecture types and enterprise applications.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Modernising the Digital Integration Hub
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Hybrid model detection and classification of lung cancer
PPT
Geologic Time for studying geology for geologist
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
A review of recent deep learning applications in wood surface defect identifi...
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
DOCX
search engine optimization ppt fir known well about this
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Architecture types and enterprise applications.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
CloudStack 4.21: First Look Webinar slides
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Modernising the Digital Integration Hub
Getting started with AI Agents and Multi-Agent Systems
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Web Crawler for Trend Tracking Gen Z Insights.pptx
Final SEM Unit 1 for mit wpu at pune .pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
NewMind AI Weekly Chronicles – August ’25 Week III
Hybrid model detection and classification of lung cancer
Geologic Time for studying geology for geologist
Module 1.ppt Iot fundamentals and Architecture
A review of recent deep learning applications in wood surface defect identifi...
Benefits of Physical activity for teenagers.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Hindi spoken digit analysis for native and non-native speakers
search engine optimization ppt fir known well about this
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game

Ado.net session11

  • 1. Developing Database Applications Using ADO.NET and XML Objectives In this session, you will learn to: Read, write, validate, and modify XML data by using the XML reader and writer classes Ver. 1.0 Session 11 Slide 1 of 24
  • 2. Developing Database Applications Using ADO.NET and XML Processing XML Data • You can process XML data in your .NET applications using the System.Xml namespace. • The System.Xml namespace contains many classes to write and read XML documents. • Using these classes, you can create an XML document, process an XML document, validate an XML document, and so on. Ver. 1.0 Session 11 Slide 2 of 24
  • 3. Developing Database Applications Using ADO.NET and XML Writing XML Data • The XmlWriter class in the System.Xml namespace provides non-cached, forward-only, and write-only access to XML data. • XmlWriter objects are created using the Create() method. • You can pass an object of XmlWriterSettings class to the Create()method in order to specify the settings or properties, which you want to enable on the XmlWriter object. If an XmlWriterSettings is not passed as a parameter, the default settings are applied. • The following line of code snippet creates an XmlWriter object that creates an XML file called myXmlFile.xml: XmlWriter writer = XmlWriter.Create(“myXmlFile.xml”,settings); Ver. 1.0 Session 11 Slide 3 of 24
  • 4. Developing Database Applications Using ADO.NET and XML Just a minute Fill in the blanks: The __________ namespace in .NET contains XML classes. Answer: System.Xml Ver. 1.0 Session 11 Slide 4 of 24
  • 5. Developing Database Applications Using ADO.NET and XML Writing XML Data (Contd.) An XML file includes elements, attributes and comments. Elements Attributes Comments • All these can be created by using various methods of XmlWriter class. Ver. 1.0 Session 11 Slide 5 of 24
  • 6. Developing Database Applications Using ADO.NET and XML Writing XML Data (Contd.) Elements can be created in two ways:  By calling the The WriteElementString()method takes WriteElementString() two value of the element. of the element and the parameters, the name method writer.WriteElementString(“Name”, “Peter”); Here, writer is an object of XmlWriter, Name is the name of the element and Peter is the value of the element.  By calling the The WriteStartElement() method takes the name of the element as a parameter. The WriteStartElement() WriteString() method to specify a value for method this element. The WriteEndElement() method to end the element tag. writer.WriteStartElement(“Name”); writer.WriteString(“Peter”); writer.WriteEndElement(); Ver. 1.0 Session 11 Slide 6 of 24
  • 7. Developing Database Applications Using ADO.NET and XML Just a minute • What is the code snippet to store the value of an integer type variable named Age into an XML file? Answer:  //writer is an object of XmlWriter writer.WriteElementString(“Age”,XmlConvert.To String(Age)); Ver. 1.0 Session 11 Slide 7 of 24
  • 8. Developing Database Applications Using ADO.NET and XML Writing XML Data (Contd.) Attributes can be created in two ways:  By calling the This method takes the name of the attribute and the value of the attribute as WriteAttributeString() parameters. method //writer is an object of //XmlWriter writer.WriteAttributeString(“O rderID”,“O001”); In the preceding code snippet, an attribute OrderID with the value  By calling the O001 is created. WriteStartAttribute() This method takes the name of the method attribute as a parameter. The WriteString() method writes the value of the attribute. The WriteEndAttribute() method ends the attribute tag. writer.WriteStartAttribute("Or derID"); writer.WriteString("O001"); Ver. 1.0 Session 11 writer.WriteEndAttribute();8 of 24 Slide
  • 9. Developing Database Applications Using ADO.NET and XML Writing XML Data (Contd.) Comments can be created in the following way:  By calling the This method takes a string as a parameter. This string is written as a WriteComment() comment in the XML file. The following method code snippet writes a comment into an XML file: //writer is an object of XmlWriter writer.WriteComment(“This XML file stores product details”); The text This XML file stores product details will be written within the <!-- and --> tags in the XML file. Ver. 1.0 Session 11 Slide 9 of 24
  • 10. Developing Database Applications Using ADO.NET and XML Just a minute Fill in the blanks:  The __________ method of the XmlWriter class is used to write comments into an XML file. Answer: WriteComment() Ver. 1.0 Session 11 Slide 10 of 24
  • 11. Developing Database Applications Using ADO.NET and XML Writing XML Data (Contd.) An XML file can be created in the following ways:  Using XmlWriter  Using XmlTextWriter  Saving a Dataset as XML data Ver. 1.0 Session 11 Slide 11 of 24
  • 12. Developing Database Applications Using ADO.NET and XML Just a minute Fill in the blanks:  The _______ option of XmlWriteMode write the contents of the dataset as XML data with the dataset structure as an inline schema. Answer: WriteSchema Ver. 1.0 Session 11 Slide 12 of 24
  • 13. Developing Database Applications Using ADO.NET and XML Reading XML Data • The XmlReader class in the System.Xml namespace provides non-cached, forward-only, and read-only access to XML data. • XmlReader objects are created using the Create() method. • You can pass an object of XmlReaderSettings class to the Create()method in order to specify the settings or properties, which you want to enable on the XmlReader object. If an XmlReaderSettings is not passed as a parameter, the default settings are applied. • The following code snippet creates an XmlReader object, which reads an XML file called books.xml: XmlReader reader = null; reader = XmlReader.Create("C:books.xml", settings); Ver. 1.0 Session 11 Slide 13 of 24
  • 14. Developing Database Applications Using ADO.NET and XML Reading XML Data (Contd.) An XML file can be read by using the following classes: XmlReader XmlTextReader Ver. 1.0 Session 11 Slide 14 of 24
  • 15. Developing Database Applications Using ADO.NET and XML Just a minute Fill in the blanks:  The _______ method of the XmlTextReader class reads the content of an element or text node in a string. Answer: ReadString() Ver. 1.0 Session 11 Slide 15 of 24
  • 16. Developing Database Applications Using ADO.NET and XML Validating XML Data An XML file can be validated against a schema using the following two classes: XmlReader XmlValidatingReader Ver. 1.0 Session 11 Slide 16 of 24
  • 17. Developing Database Applications Using ADO.NET and XML Validating XML Data (Contd.) • The following code snippet validates an XML file against a schema using XmlReader: XmlSchemaSet schemaSet = new Create the XmlSchemaSet XmlSchemaSet(); class. schemaSet.Add("urn:product Add the schema to the collection. -schema",C:products.xsd"); Set the validation settings. XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas = schemaSet; Associate the ValidationEventHandler settings.ValidationEventHandler to detect validation errors. += new alidationEventHandler (ValidationCallBack); Ver. 1.0 Session 11 Slide 17 of 24
  • 18. Developing Database Applications Using ADO.NET and XML Validating XML Data (Contd.) XmlReader reader = Create the XmlReader XmlReader.Create object. ("C:products.xml“,settings); while (reader.Read()); Parse the file Console.ReadLine(); Ver. 1.0 Session 11 Slide 18 of 24
  • 19. Developing Database Applications Using ADO.NET and XML Validating XML Data (Contd.) • The following code snippet validates an XML file against a schema using XmlValidatingReader: XmlTextReader reader = new Read the products.xml file. XmlTextReader ("C:products.xml"); XmlValidatingReader Add validation support the validatingReader = new XmlTextReader object. XmlValidatingReader(reader); validatingReader.ValidationType Set validation type as Schema. = ValidationType.Schema; Ver. 1.0 Session 11 Slide 19 of 24
  • 20. Developing Database Applications Using ADO.NET and XML Modifying XML Data Using DiffGrams DiffGram: Is an XML format that identifies current and original versions of data elements. Preserves information about changes to the data in the dataset so that you can choose whether to accept or reject the changes when you read the XML data back to the dataset. Is created in the following way: ds.WriteXml("C:Employee DataSet object Details.xml", Name of the XML file XmlWriteMode.DiffGram); Ver. 1.0 Session 11 Slide 20 of 24
  • 21. Developing Database Applications Using ADO.NET and XML Demo: Manipulating XML Data Problem Statement: Tebisco has its central office in New York and several branch offices across the United States. Tebisco collaborates with various recruitment agencies for hiring purposes. Currently, only the HR management team at the central office is provided with the details of the recruitment agencies. In addition, only the central office interacts with these recruitment agencies. If the branch offices need to interact with the recruitment agencies, they first have to interact with the central office. However, this process is taking time and, therefore, it has been decided to send the details of the recruitment agencies to the branch offices in a suitable format. Ver. 1.0 Session 11 Slide 21 of 24
  • 22. Developing Database Applications Using ADO.NET and XML Demo: Manipulating XML Data (Contd.) You are a developer in Tebisco. You have been asked to create an application that will retrieve the records stored in the RecruitmentAgencies table into a dataset and perform the following tasks: 1. Save the dataset as XML. 2. Save the dataset as a DiffGram. Ver. 1.0 Session 11 Slide 22 of 24
  • 23. Developing Database Applications Using ADO.NET and XML Summary In this session, you learned that:  System.Xml namespace contains XML classes. This namespace contains many classes to read and write XML documents.  The XmlWriter class in the System.Xml namespace provides non-cached, forward-only, and write-only access to XML data. This class can be used to write either a stream of data or a text data.  The XmlReader class in the System.Xml namespace provides non-cached, forward-only, and read-only access to XML data. If the XML file is not well formed, the XmlReader raises an XmlException. Ver. 1.0 Session 11 Slide 23 of 24
  • 24. Developing Database Applications Using ADO.NET and XML Summary (Contd.) An XML document can be validated against a schema by using the following two classes:  XmlReader  XmlValidatingReader  A DiffGram is an XML format that identifies current and original versions of data elements. Ver. 1.0 Session 11 Slide 24 of 24

Editor's Notes

  • #2: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #3: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #4: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #5: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #6: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #7: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #8: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #9: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #10: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #11: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #12: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #13: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #14: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #15: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #16: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #17: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #18: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #19: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #20: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #21: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #22: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #23: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #24: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.
  • #25: Introduce the students to the course by asking them what they know about forensics. Next, ask the students what they know about system forensics and why is it required in organizations dependent on IT. This could be a brief discussion of about 5 minutes. Lead the discussion to the objectives of this chapter.