SlideShare a Scribd company logo
Module 12: Reading and Writing XML Data
Overview Overview of XML Architecture in ASP.NET  XML and the DataSet Object Working with XML Data Using the XML Web Server Control
Lesson:  Overview of XML Architecture in ASP.NET What is XML? XML Core Technologies
What is XML? <?xml version=&quot;1.0&quot;?>  <authors> <author ID=&quot;1&quot;> <name>Jay</name> </author> <!-- There are more authors. --> </authors> Provides a uniform method for describing and exchanging structured data  You can define your own elements and attributes Elements can be nested Valid XML vs. Well-formed XML Processing Instruction Elements Attributes Comments
XML Core Technologies XML Schema definition  Defines the required structure of a valid XML document Extensible Stylesheet Language Transformation  Transforms the content of a source XML document into another document that is different in format or structure XML Path Language  Addresses parts of an XML document Document Object Model Object model for programmatically working with XML documents in memory XML Query  Easily implementable language in which queries are concise and easily understood
Lesson: XML and the DataSet Object Why use XML with DataSets? Overview of XML and DataSets The XML-Based Methods of the DataSet Object Demonstration: Reading and Writing XML to and from a DataSet Practice: Using the ReadXml Method Creating Nested XML Data Demonstration: Creating Nested XML
Why Use XML with Datasets? XML is the universal format for exchanging data on the Internet Datasets serialize data as XML  XML provides a convenient format for transferring the contents of a dataset to and from remote clients  XML objects synchronize and transform data  Human Readable Mainframe Readable XML File Or Stream Browser Readable Web Server DataSet Firewall
Overview of XML and Datasets XML File DataSet Object XmlDataDocument Object XslTransform Object XML or  HTML File Database DataAdapter ReadXML Doc.Save WriteXML XSLT File XML File XML File
Use ReadXml to load data from a file or stream Use WriteXml to write XML data to a file or stream Use GetXml to write data to a string variable The XML-Based Methods of the DataSet Object DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath(&quot;filename.xml&quot;));   DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(&quot;select * from Authors&quot;, conn); da.Fill(ds); ds.WriteXml(Server.MapPath(&quot;filename.xml&quot;));  string strXmlDS = ds.GetXml();   Visual Basic .NET Code Example
Demonstration:  Reading and Writing XML to and from a DataSet Reading XML Create a DataSet Load DataSet from an XML file Display in DataGrid Writing XML Create DataSet from database Create an XML file from a DataSet
Practice: Using the ReadXml Method Students will: Create a  DataSet Load a  DataSet  from an XML file Display in a  DataGrid Time: 5 Minutes
By default, the output of DataTables is sequential  To make XML nested, make the DataRelation nested Sequential   Nested Creating Nested XML Data Dim dr As New DataRelation _ (&quot;name&quot;, parentCol,  childCol) dr.Nested = True ds.Relations.Add(dr) <Title name=&quot;title1&quot; /> <Title name=&quot;title2&quot; /> <Title name=&quot;title3&quot; /> <Publisher name=&quot;pub1&quot; /> <Publisher name=&quot;pub2&quot; /> <Publisher name=&quot;pub1&quot; > <Title name=&quot;title1&quot; /> <Title name=&quot;title3&quot; /> </Publisher> <Publisher name=&quot;pub2&quot; > <Title name=&quot;title2&quot; /> </Publisher> DataRelation dr = new DataRelation(&quot;name&quot;, parentCol,  childCol); dr.Nested = true; ds.Relations.Add(dr);
Demonstration:  Creating Nested XML WriteXml out of a DataSet without nesting View the resulting XML file WriteXml out of a DataSet with nesting View the resulting XML file
Lesson: Working with XML Data Overview of Synchronizing a DataSet with an XmlDataDocument How to Synchronize a DataSet with an XmlDataDocument Working with an XmlDataDocument Transforming XML Data with XSLT Demonstration: Transforming Data with XSLT
Overview of Synchronizing a DataSet with an XmlDataDocument Database DataAdapter DataSet Tables XmlDataDocument XML Transformations Other XML Document Types XML Document Navigation Synchronized System.Data System.Xml
Store XML Data into an XmlDataDocument Store a DataSet in an XmlDataDocument How to Synchronize a DataSet with an XmlDataDocument Dim ds As New DataSet() 'fill in ds Dim objXmlDataDoc As New XmlDataDocument(ds) XmlDataDocument objXmlDataDoc = new XmlDataDocument(); objXmlDataDoc.Load(Server.MapPath (&quot;file.xml&quot;)); -or- objXmlDataDoc.DataSet.ReadXml(Server.MapPath (&quot;file.xml&quot;)); DataSet ds = new DataSet(); //fill in ds objXmlDataDoc = new XmlDataDocument(ds); Dim objXmlDataDoc As New XmlDataDocument() objXmlDataDoc.Load(Server.MapPath (&quot;file.xml&quot;)) -or- objXmlDataDoc.DataSet.ReadXml(Server.MapPath (&quot;file.xml&quot;))
Working with an XmlDataDocument Display data in a list-bound control Extract Dataset rows as XML Use XML DOM methods XmlDataDocument  inherits from  XmlDocument Apply an XSLT transformation XslTransform  object dg.DataSource = objXmlDataDoc.DataSet Dim elem As XmlElement elem = objXmlDataDoc.GetElementFromRow _ (ds.Tables(0).Rows(1)) XmlElement elem; elem = objXmlDataDoc.GetElementFromRow(ds.Tables[0].Rows[1]);  dg.DataSource = objXmlDataDoc.DataSet;
Transforming XML Data with XSLT Create XmlDataDocument Create XSLTransform object and call Transform method Dim ds As New DataSet() 'fill in DataSet ... Dim xmlDoc As New XmlDataDocument(ds) Dim xslTran As New XslTransform() xslTran.Load(Server.MapPath(&quot;PubTitles.xsl&quot;)) Dim writer As New XmlTextWriter _ (Server.MapPath(&quot;PubTitles_output.html&quot;), _ System.Text.Encoding.UTF8) xslTran.Transform(xmlDoc, Nothing, writer) writer.Close() C# Code Example
Demonstration:  Transforming Data with XSLT Create a DataSet with two DataTables Create XslTransform Transform the DataSet into HTML document
Lesson: Using the XML Web Server Control What is the XML Web Server Control? Loading and Saving XML Data Demonstration: Using the XML Web Server Control
What is the XML Web Server Control? Write to an XML document Writes the results of an XSLT Transformations into a Web page <asp:Xml id=&quot; Xml1 &quot;  Document=&quot; XmlDocument object to display &quot; DocumentContent=&quot; String of XML &quot;  DocumentSource=&quot; Path to XML Document &quot;  Transform=&quot; XslTransform object &quot;  TransformSource=&quot; Path to XSL Document &quot;  runat=&quot;server&quot;/>
Loading and Saving XML Data XML Web server control (in the Web Form) Loading data dynamically (in the code-behind page) Saving data (in the code-behind page) xmlCtl.Document.Save(Server.MapPath(&quot;text.xml&quot;))   xmlCtl.Document.Load(Server.MapPath(&quot;text.xml&quot;))  <asp:Xml id=&quot;xmlCtl&quot; runat=&quot;server&quot; />  xmlCtl.Document.Save(Server.MapPath(&quot;text.xml&quot;)) ; xmlCtl.Document.Load(Server.MapPath(&quot;text.xml&quot;));
Demonstration: Using the XML Web Server Control Add the XML Web server control to a Web Form Set the DocumentSource property to read an XML file View the result Set the TransformSource property to read an XSLT file View the result
Review Overview of XML Architecture in ASP.NET  XML and the DataSet Object Working with XML Data Using the XML Web Server Control
Lab 12: Reading XML Data Medical Medical.aspx Benefits Home Page Default.aspx Life Insurance Life.aspx Retirement Retirement.aspx Dental Dental.aspx Dentists Doctors Doctors.aspx  Doctors Logon Page Login.aspx Registration Register.aspx Coho Winery Prospectus Prospectus.aspx XML Web  Service dentalService1.asmx  Page Header Header.ascx ASPState tempdb Lab Web Application User Control namedate.ascx Menu  Component Class1.vb or Class1.cs XML Files Web. config

More Related Content

PPT
2310 b 11
PPT
2310 b 13
PPT
2310 b 07
PPT
2310 b 06
PDF
Ajax and xml
PPT
2310 b 17
PPT
Inner core of Ajax
2310 b 11
2310 b 13
2310 b 07
2310 b 06
Ajax and xml
2310 b 17
Inner core of Ajax

What's hot (20)

PPT
PHP - Introduction to PHP AJAX
PPTX
Introduction about-ajax-framework
PPTX
Ajax Technology
PPT
PPT
Ajax and PHP
PPT
PDF
Introduction to ajax
PPT
Ajax Ppt
DOCX
Jquery Ajax
PPTX
What is Ajax technology?
PPTX
Database connectivity in asp.net
PPT
Ajax Introduction
PDF
ASP.NET- database connectivity
PPT
Asynchronous JavaScript & XML (AJAX)
PDF
PPTX
Introduction to ajax
PPT
PDF
Web II - 02 - How ASP.NET Works
PPT
PHP - Introduction to PHP AJAX
Introduction about-ajax-framework
Ajax Technology
Ajax and PHP
Introduction to ajax
Ajax Ppt
Jquery Ajax
What is Ajax technology?
Database connectivity in asp.net
Ajax Introduction
ASP.NET- database connectivity
Asynchronous JavaScript & XML (AJAX)
Introduction to ajax
Web II - 02 - How ASP.NET Works
Ad

Similar to 2310 b 12 (20)

PPT
Processing XML with Java
PPT
[DSBW Spring 2010] Unit 10: XML and Web And beyond
PPT
PPT
6 311 W
PPT
6 311 W
PPT
SimpleXML In PHP 5
PPTX
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
PPT
Dxl As A Lotus Domino Integration Tool
PDF
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
PPTX
PPT
Java XML Parsing
PPT
Php Simple Xml
PPT
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
PPT
Sax Dom Tutorial
PPT
Javascript2839
PPT
PPT
XML Databases
PPT
XML Transformations With PHP
PDF
Import web resources using R Studio
PPT
Processing XML with Java
[DSBW Spring 2010] Unit 10: XML and Web And beyond
6 311 W
6 311 W
SimpleXML In PHP 5
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Dxl As A Lotus Domino Integration Tool
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
Java XML Parsing
Php Simple Xml
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Sax Dom Tutorial
Javascript2839
XML Databases
XML Transformations With PHP
Import web resources using R Studio
Ad

More from Krazy Koder (20)

PPT
2310 b xd
PPT
2310 b xd
PPT
2310 b xd
PPT
2310 b xc
PPT
2310 b xb
PPT
2310 b 16
PPT
2310 b 16
PPT
2310 b 15
PPT
2310 b 15
PPT
2310 b 14
PPT
2310 b 10
PPT
2310 b 09
PPT
2310 b 08
PPT
2310 b 08
PPT
2310 b 08
PPT
2310 b 05
PPT
2310 b 04
PPT
2310 b 03
PPT
2310 b 02
PPT
2310 b 01
2310 b xd
2310 b xd
2310 b xd
2310 b xc
2310 b xb
2310 b 16
2310 b 16
2310 b 15
2310 b 15
2310 b 14
2310 b 10
2310 b 09
2310 b 08
2310 b 08
2310 b 08
2310 b 05
2310 b 04
2310 b 03
2310 b 02
2310 b 01

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation theory and applications.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
1. Introduction to Computer Programming.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
August Patch Tuesday
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Machine learning based COVID-19 study performance prediction
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
TLE Review Electricity (Electricity).pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation theory and applications.pdf
A Presentation on Artificial Intelligence
1. Introduction to Computer Programming.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
Univ-Connecticut-ChatGPT-Presentaion.pdf
Empathic Computing: Creating Shared Understanding
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
Building Integrated photovoltaic BIPV_UPV.pdf
Getting Started with Data Integration: FME Form 101
gpt5_lecture_notes_comprehensive_20250812015547.pdf
A comparative study of natural language inference in Swahili using monolingua...
August Patch Tuesday
Unlocking AI with Model Context Protocol (MCP)
Machine learning based COVID-19 study performance prediction
MIND Revenue Release Quarter 2 2025 Press Release
TLE Review Electricity (Electricity).pptx

2310 b 12

  • 1. Module 12: Reading and Writing XML Data
  • 2. Overview Overview of XML Architecture in ASP.NET XML and the DataSet Object Working with XML Data Using the XML Web Server Control
  • 3. Lesson: Overview of XML Architecture in ASP.NET What is XML? XML Core Technologies
  • 4. What is XML? <?xml version=&quot;1.0&quot;?> <authors> <author ID=&quot;1&quot;> <name>Jay</name> </author> <!-- There are more authors. --> </authors> Provides a uniform method for describing and exchanging structured data You can define your own elements and attributes Elements can be nested Valid XML vs. Well-formed XML Processing Instruction Elements Attributes Comments
  • 5. XML Core Technologies XML Schema definition Defines the required structure of a valid XML document Extensible Stylesheet Language Transformation Transforms the content of a source XML document into another document that is different in format or structure XML Path Language Addresses parts of an XML document Document Object Model Object model for programmatically working with XML documents in memory XML Query Easily implementable language in which queries are concise and easily understood
  • 6. Lesson: XML and the DataSet Object Why use XML with DataSets? Overview of XML and DataSets The XML-Based Methods of the DataSet Object Demonstration: Reading and Writing XML to and from a DataSet Practice: Using the ReadXml Method Creating Nested XML Data Demonstration: Creating Nested XML
  • 7. Why Use XML with Datasets? XML is the universal format for exchanging data on the Internet Datasets serialize data as XML XML provides a convenient format for transferring the contents of a dataset to and from remote clients XML objects synchronize and transform data Human Readable Mainframe Readable XML File Or Stream Browser Readable Web Server DataSet Firewall
  • 8. Overview of XML and Datasets XML File DataSet Object XmlDataDocument Object XslTransform Object XML or HTML File Database DataAdapter ReadXML Doc.Save WriteXML XSLT File XML File XML File
  • 9. Use ReadXml to load data from a file or stream Use WriteXml to write XML data to a file or stream Use GetXml to write data to a string variable The XML-Based Methods of the DataSet Object DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath(&quot;filename.xml&quot;)); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(&quot;select * from Authors&quot;, conn); da.Fill(ds); ds.WriteXml(Server.MapPath(&quot;filename.xml&quot;)); string strXmlDS = ds.GetXml(); Visual Basic .NET Code Example
  • 10. Demonstration: Reading and Writing XML to and from a DataSet Reading XML Create a DataSet Load DataSet from an XML file Display in DataGrid Writing XML Create DataSet from database Create an XML file from a DataSet
  • 11. Practice: Using the ReadXml Method Students will: Create a DataSet Load a DataSet from an XML file Display in a DataGrid Time: 5 Minutes
  • 12. By default, the output of DataTables is sequential To make XML nested, make the DataRelation nested Sequential Nested Creating Nested XML Data Dim dr As New DataRelation _ (&quot;name&quot;, parentCol, childCol) dr.Nested = True ds.Relations.Add(dr) <Title name=&quot;title1&quot; /> <Title name=&quot;title2&quot; /> <Title name=&quot;title3&quot; /> <Publisher name=&quot;pub1&quot; /> <Publisher name=&quot;pub2&quot; /> <Publisher name=&quot;pub1&quot; > <Title name=&quot;title1&quot; /> <Title name=&quot;title3&quot; /> </Publisher> <Publisher name=&quot;pub2&quot; > <Title name=&quot;title2&quot; /> </Publisher> DataRelation dr = new DataRelation(&quot;name&quot;, parentCol, childCol); dr.Nested = true; ds.Relations.Add(dr);
  • 13. Demonstration: Creating Nested XML WriteXml out of a DataSet without nesting View the resulting XML file WriteXml out of a DataSet with nesting View the resulting XML file
  • 14. Lesson: Working with XML Data Overview of Synchronizing a DataSet with an XmlDataDocument How to Synchronize a DataSet with an XmlDataDocument Working with an XmlDataDocument Transforming XML Data with XSLT Demonstration: Transforming Data with XSLT
  • 15. Overview of Synchronizing a DataSet with an XmlDataDocument Database DataAdapter DataSet Tables XmlDataDocument XML Transformations Other XML Document Types XML Document Navigation Synchronized System.Data System.Xml
  • 16. Store XML Data into an XmlDataDocument Store a DataSet in an XmlDataDocument How to Synchronize a DataSet with an XmlDataDocument Dim ds As New DataSet() 'fill in ds Dim objXmlDataDoc As New XmlDataDocument(ds) XmlDataDocument objXmlDataDoc = new XmlDataDocument(); objXmlDataDoc.Load(Server.MapPath (&quot;file.xml&quot;)); -or- objXmlDataDoc.DataSet.ReadXml(Server.MapPath (&quot;file.xml&quot;)); DataSet ds = new DataSet(); //fill in ds objXmlDataDoc = new XmlDataDocument(ds); Dim objXmlDataDoc As New XmlDataDocument() objXmlDataDoc.Load(Server.MapPath (&quot;file.xml&quot;)) -or- objXmlDataDoc.DataSet.ReadXml(Server.MapPath (&quot;file.xml&quot;))
  • 17. Working with an XmlDataDocument Display data in a list-bound control Extract Dataset rows as XML Use XML DOM methods XmlDataDocument inherits from XmlDocument Apply an XSLT transformation XslTransform object dg.DataSource = objXmlDataDoc.DataSet Dim elem As XmlElement elem = objXmlDataDoc.GetElementFromRow _ (ds.Tables(0).Rows(1)) XmlElement elem; elem = objXmlDataDoc.GetElementFromRow(ds.Tables[0].Rows[1]); dg.DataSource = objXmlDataDoc.DataSet;
  • 18. Transforming XML Data with XSLT Create XmlDataDocument Create XSLTransform object and call Transform method Dim ds As New DataSet() 'fill in DataSet ... Dim xmlDoc As New XmlDataDocument(ds) Dim xslTran As New XslTransform() xslTran.Load(Server.MapPath(&quot;PubTitles.xsl&quot;)) Dim writer As New XmlTextWriter _ (Server.MapPath(&quot;PubTitles_output.html&quot;), _ System.Text.Encoding.UTF8) xslTran.Transform(xmlDoc, Nothing, writer) writer.Close() C# Code Example
  • 19. Demonstration: Transforming Data with XSLT Create a DataSet with two DataTables Create XslTransform Transform the DataSet into HTML document
  • 20. Lesson: Using the XML Web Server Control What is the XML Web Server Control? Loading and Saving XML Data Demonstration: Using the XML Web Server Control
  • 21. What is the XML Web Server Control? Write to an XML document Writes the results of an XSLT Transformations into a Web page <asp:Xml id=&quot; Xml1 &quot; Document=&quot; XmlDocument object to display &quot; DocumentContent=&quot; String of XML &quot; DocumentSource=&quot; Path to XML Document &quot; Transform=&quot; XslTransform object &quot; TransformSource=&quot; Path to XSL Document &quot; runat=&quot;server&quot;/>
  • 22. Loading and Saving XML Data XML Web server control (in the Web Form) Loading data dynamically (in the code-behind page) Saving data (in the code-behind page) xmlCtl.Document.Save(Server.MapPath(&quot;text.xml&quot;)) xmlCtl.Document.Load(Server.MapPath(&quot;text.xml&quot;)) <asp:Xml id=&quot;xmlCtl&quot; runat=&quot;server&quot; /> xmlCtl.Document.Save(Server.MapPath(&quot;text.xml&quot;)) ; xmlCtl.Document.Load(Server.MapPath(&quot;text.xml&quot;));
  • 23. Demonstration: Using the XML Web Server Control Add the XML Web server control to a Web Form Set the DocumentSource property to read an XML file View the result Set the TransformSource property to read an XSLT file View the result
  • 24. Review Overview of XML Architecture in ASP.NET XML and the DataSet Object Working with XML Data Using the XML Web Server Control
  • 25. Lab 12: Reading XML Data Medical Medical.aspx Benefits Home Page Default.aspx Life Insurance Life.aspx Retirement Retirement.aspx Dental Dental.aspx Dentists Doctors Doctors.aspx Doctors Logon Page Login.aspx Registration Register.aspx Coho Winery Prospectus Prospectus.aspx XML Web Service dentalService1.asmx Page Header Header.ascx ASPState tempdb Lab Web Application User Control namedate.ascx Menu Component Class1.vb or Class1.cs XML Files Web. config