Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Processing SoftUni Team Database Applications Technical Trainers

Similar presentations


Presentation on theme: "XML Processing SoftUni Team Database Applications Technical Trainers"— Presentation transcript:

1 XML Processing SoftUni Team Database Applications Technical Trainers
Software University © Software University Foundation – This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

2 Table of Contents What is XML? LINQ to XML

3 What is XML?

4 XML – Example <?xml version="1.0"?>
<library name="Developer's Library"> <book> <title>Professional C# 4.0 and .NET 4</title> <author>Christian Nagel</author> <isbn> </isbn> </book> <title>Teach Yourself XML in 10 Minutes</title> <author>Andrew H. Watt</author> <isbn> </isbn> </library>

5 What is XML? XML (eXtensible Markup Language)
Universal notation (data format / language) for describing structured data using text with tags The data is stored together with the meta-data about it Used to describe other languages (formats) for data representation

6 What is XML? (2) XML looks like HTML
Text based language, uses tags and attributes Industrial standard, supported by the W3C ( Independent of the hardware platform, OS and programming languages

7 XML – Example XML header tag (prolog) Attribute (key / value pair)
<?xml version="1.0"?> <library name="Developer's Library"> <book> <title>Professional C# 4.0 and .NET 4</title> <author>Christian Nagel</author> <isbn> </isbn> </book> <title>Teach Yourself XML in 10 Minutes</title> <author>Andrew H. Watt</author> <isbn> </isbn> </library> Root (document) element Element Opening tag Closing tag Element value

8 XML and HTML Similarities between XML and HTML
Both are text based notations Both use tags and attributes Differences between XML and HTML HTML is a language, and XML is a syntax for describing other languages (meta-language) HTML describes the formatting of information, XML describes structured information XML requires the documents to be well-formed

9 Well-Formed XML Documents
Means "syntactically correct XML document" All tags should be closed in the correct order of nesting Attributes should always be closed The document should contain only one root element Tag and attribute names retain certain restrictions

10 Well-Formed XML Documents (2)
Example of incorrect XML document Open / close tags do not match Unclosed attribute values Invalid characters, invalid spacing Check for well-formed XML online: <xml> <button bug! value="OK name="b1"> <animation source="trailer.avi"> 1 < 2 < 3 </click-button> < / xml >

11 XML: Benefits Benefits of XML:
XML is human readable (unlike binary formats) Store any kind of structured data Data comes with self-describing meta-data Full Unicode support Exchange data between different systems Custom XML-based languages can be designed for certain apps Parsers available for virtually all languages and platforms

12 When to Use XML? (2) Disadvantages of XML:
XML data is bigger (takes more space) than in binary formats More memory consumption, more network traffic, more hard-disk space, more resources Decreased performance CPU consumption: need of parsing / constructing the XML tags XML is not suitable for all kinds of data E.g. graphics, images and video clips

13 LINQ to XML

14 LINQ to XML LINQ to XML LINQ to XML classes:
Use the power of LINQ to process XML data Easily read, search, write, modify XML documents LINQ to XML classes: XDocument – represents a LINQ-enabled XML document (containing prolog, root element, …)

15 LINQ to XML Classes LINQ to XML classes:
XElement – represents an XML element in LINQ to XML Methods: Parse(…), Save(), RemoveAtributes(…), SetElementValue(…), SetAtributeValue(…), WriteTo(…) XAttribute Name / value attribute pair

16 LINQ to XML – Searching with LINQ
Searching in XML with LINQ is like searching with LINQ in array XDocument xmlDoc = XDocument.Load("../../books.xml"); var books = from book in xmlDoc.Descendants("book") where book.Element("title").Value.Contains("4.0") select new { Title = book.Element("title").Value, Author = book.Element("author").Value }; foreach (var book in books) { Console.WriteLine(book); }

17 Creating XML with XElement
Need to create this XML fragment? <books> <book> <author>Don Box</author> <title>Essential .NET</title> </book> XElement books = new XElement("books", new XElement("book", new XElement("author", "Don Box"), new XElement("title", "ASP.NET") ) );

18 Additional XML classes to consider:
XML Document – old version of Xdocument  XmlReader/XmlWriter - huge XML which cannot fit into memory

19 XML Processing https://softuni.bg/courses/
© Software University Foundation – This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

20 License This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" license Attribution: this work may contain portions from "Databases" course by Telerik Academy under CC-BY-NC-SA license © Software University Foundation – This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

21 Free Trainings @ Software University
Software University Foundation – softuni.org Software University – High-Quality Education, Profession and Job for Software Developers softuni.bg Software Facebook facebook.com/SoftwareUniversity Software YouTube youtube.com/SoftwareUniversity Software University Forums – forum.softuni.bg © Software University Foundation – This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.


Download ppt "XML Processing SoftUni Team Database Applications Technical Trainers"

Similar presentations


Ads by Google