SlideShare a Scribd company logo
1 of 24
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

What's hot

12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objects
Phúc Đỗ
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
Young Alista
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
Phúc Đỗ
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
Surinder Kaur
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
imypraz
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's New
Ted Pennings
 

What's hot (20)

12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objects
 
C# Advanced L07-Design Patterns
C# Advanced L07-Design PatternsC# Advanced L07-Design Patterns
C# Advanced L07-Design Patterns
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
S313937 cdi dochez
S313937 cdi dochezS313937 cdi dochez
S313937 cdi dochez
 
Serialization in java
Serialization in javaSerialization in java
Serialization in java
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
 
The xml
The xmlThe xml
The xml
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
UML and You
UML and YouUML and You
UML and You
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
 
Cordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptCordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced Javascript
 
Hibernate
HibernateHibernate
Hibernate
 
Session 09 - OOPS
Session 09 - OOPSSession 09 - OOPS
Session 09 - OOPS
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NET
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's New
 

Similar to Ado.net session11

Ado.net session13
Ado.net session13Ado.net session13
Ado.net session13
Niit Care
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializing
ssusere19c741
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.net
glubox
 
04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07
Niit Care
 
It seminar-xml serialization
It seminar-xml serializationIt seminar-xml serialization
It seminar-xml serialization
Priyojit Mondal
 
It seminar-xml serialization
It seminar-xml serializationIt seminar-xml serialization
It seminar-xml serialization
Priyojit Mondal
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03
Niit Care
 
Ado.net session14
Ado.net session14Ado.net session14
Ado.net session14
Niit Care
 
Techniques for Writing XML Data.pptx
Techniques for Writing XML Data.pptxTechniques for Writing XML Data.pptx
Techniques for Writing XML Data.pptx
lekha572836
 

Similar to Ado.net session11 (20)

Xml writers
Xml writersXml writers
Xml writers
 
Ado.net session13
Ado.net session13Ado.net session13
Ado.net session13
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializing
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12
 
Session 4
Session 4Session 4
Session 4
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMING
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.net
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Ian 2014.10.24 weekly report
Ian 2014.10.24 weekly reportIan 2014.10.24 weekly report
Ian 2014.10.24 weekly report
 
04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07
 
It seminar-xml serialization
It seminar-xml serializationIt seminar-xml serialization
It seminar-xml serialization
 
It seminar-xml serialization
It seminar-xml serializationIt seminar-xml serialization
It seminar-xml serialization
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03
 
Ado.net session14
Ado.net session14Ado.net session14
Ado.net session14
 
Entity framework1
Entity framework1Entity framework1
Entity framework1
 
Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET components
 
Techniques for Writing XML Data.pptx
Techniques for Writing XML Data.pptxTechniques for Writing XML Data.pptx
Techniques for Writing XML Data.pptx
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

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

  1. 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.
  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.