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


                In this session, you will learn to:
                   Read and write XML data using DOM API




     Ver. 1.0                      Session 13              Slide 1 of 10
Developing Database Applications Using ADO.NET and XML
Processing XML Data Using DOM


               Many applications need the ability to:
                  Read an entire XML document into memory
                  Access XML content in any order
                  Modify the XML content in memory
               The XML Document Object Model (DOM) is an Application
               Programming Interface (API) that provides full read-write
               random-access capabilities for reading and writing XML
               data.




    Ver. 1.0                    Session 13                        Slide 2 of 10
Developing Database Applications Using ADO.NET and XML
Reading XML Data into DOM


               •   You can load an XML document into a DOM tree using the
                   XmlDocument class.
               •   The XmlDocument class provides the following two methods
                   to load an XML document into memory:
                    Load(): This method loads XML data from a stream, a string, an
                     XmlReader, or a TextReader.
                       XmlDocument doc = new XmlDocument();
                       XmlTextReader reader = new
                       XmlTextReader("C:books.xml");
                       reader.Read();
                       doc.Load(reader);
                    LoadXml(): This method is used load an XML file from a string.
                       XmlDocument doc = new XmlDocument();
                       doc.LoadXml(("<BOOKDETAILS><BOOK><BOOKNAME>The
                       DaVinci Code</BOOKNAME><AUTHOR>Dan
                       Brown</AUTHOR></BOOK></BOOKDETAILS>"));

    Ver. 1.0                        Session 13                            Slide 3 of 10
Developing Database Applications Using ADO.NET and XML
Reading XML Data into DOM (Contd.)


                Accessing child nodes:
                 The XmlNode.ChildNodes property is an XmlNodeList that
                  contains all the child nodes of the node.
                 Some of the other properties of the XmlNode class are described
                  in the following table.
                  Property          Description
                  FirstChild        It is used to access the first child under the reference node.

                  LastChild         It is used to access the last child under the reference node.

                  NextSibling       It is used to access the node immediately next to the reference
                                    node.
                  PreviousSibling   It is used to access the node immediately preceding the reference
                                    node.
                  ParentNode        It is used to access the parent node of the reference node.




     Ver. 1.0                        Session 13                                                      Slide 4 of 10
Developing Database Applications Using ADO.NET and XML
Writing XML Data from DOM


               Creating new nodes in the DOM tree:
                You can create new nodes using the Create<Node_Type>
                 method of XmlDocument, where <Node_Type> is the type of
                 node.
                After creating the new nodes, you need to insert them into the
                 DOM tree using the following methods.

               Property         Description

               InsertBefore()   It is used to insert a node before the referenced node.

               InsertAfter()    It is used to insert a node after the referenced node.

               AppendChild()    It is used to add the node to the end of all the child nodes for the given node.

               PrependChild()   It is used to add the node to the beginning of all the child nodes for the given
                                node.
               Append()         It is used to add an XmlAttribute node to the end of the attribute
                                collection that is associated with an element.




    Ver. 1.0                         Session 13                                                    Slide 5 of 10
Developing Database Applications Using ADO.NET and XML
Writing XML Data from DOM (Contd.)


                 Creating an XML Declaration: The XmlDocument class has
                  a CreateXmlDeclaration()method that is used for
                  creating XML declarations. This class has the following
                  parameters:
                     Version: The version should be 1.0.
                     Encoding: Encoding is used when you save the XmlDocument
                      to a file or stream. Encoding should be set to a string supported
                      by the Encoding class, as otherwise, the Save() method will
                      not work.
                     Standalone: The value is either yes or no. If null is passed,
                      the Save() method does not write a standalone attribute in the
                      XML declaration.




     Ver. 1.0                      Session 13                                  Slide 6 of 10
Developing Database Applications Using ADO.NET and XML
Writing XML Data from DOM (Contd.)


                 Creating elements: The CreateElement() method is used for
                  creating XML elements.
                   Consider the following XML File called books.xml:
                   <BOOK BOOKID='B001'>
                     <BOOKNAME>The DaVinci Code</BOOKNAME>
                     <AUTHOR>Dan Brown</AUTHOR>
                   </BOOK>
                   Consider the following code snippet:
                   XmlElement element =
                   doc.CreateElement("PRICE");                 Name of the element
                   XmlText text =
                   doc.CreateTextNode("20");                   Value of the element
                   On executing the preceding code, the books.xml becomes:
                   <BOOK BOOKID='B001'>
                     <BOOKNAME>The DaVinci Code</BOOKNAME>
                     <AUTHOR>Dan Brown</AUTHOR>
                     <PRICE>20</PRICE>
                   </BOOK>
     Ver. 1.0                      Session 13                                   Slide 7 of 10
Developing Database Applications Using ADO.NET and XML
Writing XML Data from DOM (Contd.)


                Deleting nodes from the DOM tree
                 You can delete nodes from a DOM tree by using the
                  RemoveChild() method.
                    Consider the following XML File called books.xml:
                    <BOOK BOOKID='B001'>
                      <BOOKNAME>The DaVinci Code</BOOKNAME>
                      <AUTHOR>Dan Brown</AUTHOR>
                    </BOOK>
                                                                  Get reference to the first
                    Consider the following code snippet:
                                                                  BOOK element.
                    XmlNode node =                                doc is an object of
                    doc.DocumentElement.FirstChild;               XmlDocument.
                    node.RemoveChild(node.FirstChild);            Remove the BOOKNAME
                                                                  element.
                    On executing the preceding code, the books.xml becomes:
                    <BOOK BOOKID='B001'>
                      <AUTHOR>Dan Brown</AUTHOR>
                    </BOOK>

     Ver. 1.0                     Session 13                                  Slide 8 of 10
Developing Database Applications Using ADO.NET and XML
Demo: Manipulating XML Data Using DOM


               Problem Statement:
                Peter is a developer in Tebisco. He has to create an
                 application that will transfer the data stored in the JobFair table
                 into an XML file called JobFair.xml. In addition, he has been
                 assigned with the following tasks:
                      Calculate the total number of job fairs held
                      Add details of a new job fair to the XML file. This new fair has the
                      following details:
                           cJobFairCode: 0006
                           vLocation: 15, Madison Street, Alabama
                           vJobFairCompany: MoreJobs Ltd.
                           mFee: 25
                           dFairDate: 2006-11-10
                  You need to develop an application that would perform these
                  tasks for Peter.



    Ver. 1.0                      Session 13                                     Slide 9 of 10
Developing Database Applications Using ADO.NET and XML
Summary


               In this session, you will learn to:
                 While the XmlReader and XmlWriter classes give you serial
                  access to an XML document, the DOM API gives you random
                  access to any element or attribute in the XML document.
                 In the .NET Framework, NamedNodeMap is implemented by
                  the XmlNamedNodeMap class, and NodeList is implemented
                  by the XmlNodeList class.
                 An XML document can be created by using the XmlDocument
                  class.




    Ver. 1.0                      Session 13                       Slide 10 of 10

More Related Content

What's hot

Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile appsIvano Malavolta
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesSanjeev Kumar Jaiswal
 
Simple xml in .net
Simple xml in .netSimple xml in .net
Simple xml in .netVi Vo Hung
 
Cordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptCordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptBinu Paul
 
The Ring programming language version 1.5.4 book - Part 28 of 185
The Ring programming language version 1.5.4 book - Part 28 of 185The Ring programming language version 1.5.4 book - Part 28 of 185
The Ring programming language version 1.5.4 book - Part 28 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 35 of 210
The Ring programming language version 1.9 book - Part 35 of 210The Ring programming language version 1.9 book - Part 35 of 210
The Ring programming language version 1.9 book - Part 35 of 210Mahmoud Samir Fayed
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming conceptsGanesh Karthik
 

What's hot (20)

ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Tp2
Tp2Tp2
Tp2
 
Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile apps
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
 
Java Programming - 06 java file io
Java Programming - 06 java file ioJava Programming - 06 java file io
Java Programming - 06 java file io
 
Ejb3 Dan Hinojosa
Ejb3 Dan HinojosaEjb3 Dan Hinojosa
Ejb3 Dan Hinojosa
 
Vba functions
Vba functionsVba functions
Vba functions
 
Simple xml in .net
Simple xml in .netSimple xml in .net
Simple xml in .net
 
Ajax
AjaxAjax
Ajax
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
Cordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptCordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced Javascript
 
Ado.net
Ado.netAdo.net
Ado.net
 
Local Storage
Local StorageLocal Storage
Local Storage
 
Phactory
PhactoryPhactory
Phactory
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
The Ring programming language version 1.5.4 book - Part 28 of 185
The Ring programming language version 1.5.4 book - Part 28 of 185The Ring programming language version 1.5.4 book - Part 28 of 185
The Ring programming language version 1.5.4 book - Part 28 of 185
 
The Ring programming language version 1.9 book - Part 35 of 210
The Ring programming language version 1.9 book - Part 35 of 210The Ring programming language version 1.9 book - Part 35 of 210
The Ring programming language version 1.9 book - Part 35 of 210
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 

Viewers also liked

Viewers also liked (11)

Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NET
 
Ado.net
Ado.netAdo.net
Ado.net
 
Vb net xp_05
Vb net xp_05Vb net xp_05
Vb net xp_05
 
Ado.net
Ado.netAdo.net
Ado.net
 
Learning VB.NET Programming Concepts
Learning VB.NET Programming ConceptsLearning VB.NET Programming Concepts
Learning VB.NET Programming Concepts
 
Ado.net
Ado.netAdo.net
Ado.net
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Visual Studio.NET
Visual Studio.NETVisual Studio.NET
Visual Studio.NET
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 

Similar to Ado.net session13

04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07Niit Care
 
04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08Niit Care
 
buildingxmlbasedapplications-180322042009.pptx
buildingxmlbasedapplications-180322042009.pptxbuildingxmlbasedapplications-180322042009.pptx
buildingxmlbasedapplications-180322042009.pptxNKannanCSE
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based ApplicationsPrabu U
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOMSurinder Kaur
 
Ado.net session11
Ado.net session11Ado.net session11
Ado.net session11Niit Care
 
12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objectsPhúc Đỗ
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.netglubox
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_javaardnetij
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Bill Buchan
 
Understanding Dom
Understanding DomUnderstanding Dom
Understanding DomLiquidHub
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializingssusere19c741
 
Xml And JSON Java
Xml And JSON JavaXml And JSON Java
Xml And JSON JavaHenry Addo
 

Similar to Ado.net session13 (20)

The xml
The xmlThe xml
The xml
 
04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07
 
04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08
 
Dom
Dom Dom
Dom
 
Xml writers
Xml writersXml writers
Xml writers
 
Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
buildingxmlbasedapplications-180322042009.pptx
buildingxmlbasedapplications-180322042009.pptxbuildingxmlbasedapplications-180322042009.pptx
buildingxmlbasedapplications-180322042009.pptx
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based Applications
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
 
Ado.net session11
Ado.net session11Ado.net session11
Ado.net session11
 
12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objects
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.net
 
Unit 2
Unit 2 Unit 2
Unit 2
 
Ch23
Ch23Ch23
Ch23
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_java
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 
Understanding Dom
Understanding DomUnderstanding Dom
Understanding Dom
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializing
 
Xml And JSON Java
Xml And JSON JavaXml And JSON Java
Xml And JSON Java
 
treeview
treeviewtreeview
treeview
 

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

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingSelcen Ozturkcan
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
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
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
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 RobisonAnna Loughnan Colquhoun
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
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
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Ado.net session13

  • 1. Developing Database Applications Using ADO.NET and XML Objectives In this session, you will learn to: Read and write XML data using DOM API Ver. 1.0 Session 13 Slide 1 of 10
  • 2. Developing Database Applications Using ADO.NET and XML Processing XML Data Using DOM Many applications need the ability to: Read an entire XML document into memory Access XML content in any order Modify the XML content in memory The XML Document Object Model (DOM) is an Application Programming Interface (API) that provides full read-write random-access capabilities for reading and writing XML data. Ver. 1.0 Session 13 Slide 2 of 10
  • 3. Developing Database Applications Using ADO.NET and XML Reading XML Data into DOM • You can load an XML document into a DOM tree using the XmlDocument class. • The XmlDocument class provides the following two methods to load an XML document into memory:  Load(): This method loads XML data from a stream, a string, an XmlReader, or a TextReader. XmlDocument doc = new XmlDocument(); XmlTextReader reader = new XmlTextReader("C:books.xml"); reader.Read(); doc.Load(reader);  LoadXml(): This method is used load an XML file from a string. XmlDocument doc = new XmlDocument(); doc.LoadXml(("<BOOKDETAILS><BOOK><BOOKNAME>The DaVinci Code</BOOKNAME><AUTHOR>Dan Brown</AUTHOR></BOOK></BOOKDETAILS>")); Ver. 1.0 Session 13 Slide 3 of 10
  • 4. Developing Database Applications Using ADO.NET and XML Reading XML Data into DOM (Contd.) Accessing child nodes:  The XmlNode.ChildNodes property is an XmlNodeList that contains all the child nodes of the node.  Some of the other properties of the XmlNode class are described in the following table. Property Description FirstChild It is used to access the first child under the reference node. LastChild It is used to access the last child under the reference node. NextSibling It is used to access the node immediately next to the reference node. PreviousSibling It is used to access the node immediately preceding the reference node. ParentNode It is used to access the parent node of the reference node. Ver. 1.0 Session 13 Slide 4 of 10
  • 5. Developing Database Applications Using ADO.NET and XML Writing XML Data from DOM Creating new nodes in the DOM tree:  You can create new nodes using the Create<Node_Type> method of XmlDocument, where <Node_Type> is the type of node.  After creating the new nodes, you need to insert them into the DOM tree using the following methods. Property Description InsertBefore() It is used to insert a node before the referenced node. InsertAfter() It is used to insert a node after the referenced node. AppendChild() It is used to add the node to the end of all the child nodes for the given node. PrependChild() It is used to add the node to the beginning of all the child nodes for the given node. Append() It is used to add an XmlAttribute node to the end of the attribute collection that is associated with an element. Ver. 1.0 Session 13 Slide 5 of 10
  • 6. Developing Database Applications Using ADO.NET and XML Writing XML Data from DOM (Contd.)  Creating an XML Declaration: The XmlDocument class has a CreateXmlDeclaration()method that is used for creating XML declarations. This class has the following parameters:  Version: The version should be 1.0.  Encoding: Encoding is used when you save the XmlDocument to a file or stream. Encoding should be set to a string supported by the Encoding class, as otherwise, the Save() method will not work.  Standalone: The value is either yes or no. If null is passed, the Save() method does not write a standalone attribute in the XML declaration. Ver. 1.0 Session 13 Slide 6 of 10
  • 7. Developing Database Applications Using ADO.NET and XML Writing XML Data from DOM (Contd.)  Creating elements: The CreateElement() method is used for creating XML elements. Consider the following XML File called books.xml: <BOOK BOOKID='B001'> <BOOKNAME>The DaVinci Code</BOOKNAME> <AUTHOR>Dan Brown</AUTHOR> </BOOK> Consider the following code snippet: XmlElement element = doc.CreateElement("PRICE"); Name of the element XmlText text = doc.CreateTextNode("20"); Value of the element On executing the preceding code, the books.xml becomes: <BOOK BOOKID='B001'> <BOOKNAME>The DaVinci Code</BOOKNAME> <AUTHOR>Dan Brown</AUTHOR> <PRICE>20</PRICE> </BOOK> Ver. 1.0 Session 13 Slide 7 of 10
  • 8. Developing Database Applications Using ADO.NET and XML Writing XML Data from DOM (Contd.) Deleting nodes from the DOM tree  You can delete nodes from a DOM tree by using the RemoveChild() method. Consider the following XML File called books.xml: <BOOK BOOKID='B001'> <BOOKNAME>The DaVinci Code</BOOKNAME> <AUTHOR>Dan Brown</AUTHOR> </BOOK> Get reference to the first Consider the following code snippet: BOOK element. XmlNode node = doc is an object of doc.DocumentElement.FirstChild; XmlDocument. node.RemoveChild(node.FirstChild); Remove the BOOKNAME element. On executing the preceding code, the books.xml becomes: <BOOK BOOKID='B001'> <AUTHOR>Dan Brown</AUTHOR> </BOOK> Ver. 1.0 Session 13 Slide 8 of 10
  • 9. Developing Database Applications Using ADO.NET and XML Demo: Manipulating XML Data Using DOM Problem Statement:  Peter is a developer in Tebisco. He has to create an application that will transfer the data stored in the JobFair table into an XML file called JobFair.xml. In addition, he has been assigned with the following tasks: Calculate the total number of job fairs held Add details of a new job fair to the XML file. This new fair has the following details: cJobFairCode: 0006 vLocation: 15, Madison Street, Alabama vJobFairCompany: MoreJobs Ltd. mFee: 25 dFairDate: 2006-11-10 You need to develop an application that would perform these tasks for Peter. Ver. 1.0 Session 13 Slide 9 of 10
  • 10. Developing Database Applications Using ADO.NET and XML Summary In this session, you will learn to:  While the XmlReader and XmlWriter classes give you serial access to an XML document, the DOM API gives you random access to any element or attribute in the XML document.  In the .NET Framework, NamedNodeMap is implemented by the XmlNamedNodeMap class, and NodeList is implemented by the XmlNodeList class.  An XML document can be created by using the XmlDocument class. Ver. 1.0 Session 13 Slide 10 of 10

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.