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 objectsPhúc Đỗ
 
C# Advanced L07-Design Patterns
C# Advanced L07-Design PatternsC# Advanced L07-Design Patterns
C# Advanced L07-Design PatternsMohammad Shaker
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserializationYoung Alista
 
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)Gandhi Ravi
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
Serialization in java
Serialization in javaSerialization in java
Serialization in javaJanu Jahnavi
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOMSurinder Kaur
 
Java Serialization
Java SerializationJava Serialization
Java Serializationimypraz
 
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 Manykenatmxm
 
Cordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptCordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptBinu Paul
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NETAbhi Arya
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's NewTed 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 session13Niit Care
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializingssusere19c741
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12RohanMistry15
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGProf Ansari
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.netglubox
 
Ian 2014.10.24 weekly report
Ian 2014.10.24 weekly reportIan 2014.10.24 weekly report
Ian 2014.10.24 weekly reportLearningTech
 
04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07Niit Care
 
It seminar-xml serialization
It seminar-xml serializationIt seminar-xml serialization
It seminar-xml serializationPriyojit Mondal
 
It seminar-xml serialization
It seminar-xml serializationIt seminar-xml serialization
It seminar-xml serializationPriyojit Mondal
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03Niit Care
 
Ado.net session14
Ado.net session14Ado.net session14
Ado.net session14Niit Care
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET componentsBình Trọng Án
 
Techniques for Writing XML Data.pptx
Techniques for Writing XML Data.pptxTechniques for Writing XML Data.pptx
Techniques for Writing XML Data.pptxlekha572836
 

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

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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?Igalia
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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...Miguel Araújo
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

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.