XML Processing SoftUni Team Database Applications Technical Trainers

Slides:



Advertisements
Similar presentations
Software Quality Assurance QA Engineering, Testing, Bug Tracking, Test Automation Software University Technical Trainers SoftUni Team.
Advertisements

AngularJS Routing Routes, Route Parameters, Templates, Location, Navigation SoftUni Team Technical Trainers Software University
AngularJS Services Built-in and Custom Services SoftUni Team Technical Trainers Software University
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
Processing Redis with.NET How to Operate with Redis Databases SoftUni Team Technical Trainers Software University
Asynchronous Web Services Writing Asynchronous Web Services SoftUni Team Technical Trainers Software University
Processing JSON in.NET JSON, JSON.NET LINQ-to-JSON and JSON to XML SoftUni Team Technical Trainers Software University
Tables, Rows, Columns, Cells, Header, Footer, Colspan, Rowspan
Doctrine The PHP ORM SoftUni Team Technical Trainers Software University
Stacks and Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
Version Control Systems
Exporting and Importing Data
Auto Mapping Objects SoftUni Team Database Applications
Static Members and Namespaces
Functional Programming
Introduction to Entity framework
Databases basics Course Introduction SoftUni Team Databases basics
Data Structures Course Overview SoftUni Team Data Structures
Introduction to MVC SoftUni Team Introduction to MVC
Deploying Web Application
PHP MVC Frameworks Course Introduction SoftUni Team Technical Trainers
PHP Fundamentals Course Introduction SoftUni Team Technical Trainers
Introduction to Entity Framework
ASP.NET Integration Testing
Mocking tools for easier unit testing
Parsing JSON JSON.NET, LINQ-to-JSON
State Management Cookies, Sessions SoftUni Team State Management
EF Code First (Advanced)
PHP MVC Frameworks MVC Fundamentals SoftUni Team Technical Trainers
C# Databases Advanced with Microsoft SQL Server
Entity Framework: Code First
Parsing XML XDocument and LINQ
Data Definition and Data Types
Install and configure theme
Balancing Binary Search Trees, Rotations
Entity Framework: Relations
Caching Data in ASP.NET MVC
Fast String Manipulation
Array and List Algorithms
Functional Programming
Transactions in Entity Framework
ASP.NET MVC Introduction
C# Advanced Course Introduction SoftUni Team C# Technical Trainers
Exporting and Importing Data
Databases Advanced Course Introduction SoftUni Team Databases Advanced
Best practices and architecture
Arrays and Multidimensional Arrays
Design & Module Development
Data Definition and Data Types
Multidimensional Arrays, Sets, Dictionaries
Extending functionality using Collections
ASP.NET REST Services SoftUni Team ASP.NET REST Services
Exporting and Importing Data
Making big SPA applications
Manual Mapping and AutoMapper Library
Functional Programming
C# Advanced Course Introduction SoftUni Team C# Technical Trainers
Exporting and Importing Data
CSS Transitions and Animations
Train the Trainers Course
Iterators and Comparators
Software Quality Assurance
Version Control Systems
JavaScript Frameworks & AngularJS
Polymorphism, Interfaces, Abstract Classes
Text Processing and Regex API
/^Hel{2}o\s*World\n$/
Lean .NET stack for building modern web apps
CSS Transitions and Animations
Iterators and Generators
Presentation transcript:

XML Processing SoftUni Team Database Applications Technical Trainers Software University http://softuni.bg © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Table of Contents What is XML? LINQ to XML

What is XML?

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>978-0-470-50225-9</isbn> </book> <title>Teach Yourself XML in 10 Minutes</title> <author>Andrew H. Watt</author> <isbn>978-0-672-32471-0</isbn> </library>

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

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

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>978-0-470-50225-9</isbn> </book> <title>Teach Yourself XML in 10 Minutes</title> <author>Andrew H. Watt</author> <isbn>978-0-672-32471-0</isbn> </library> Root (document) element Element Opening tag Closing tag Element value

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

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

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: http://xmlvalidation.com <xml> <button bug! value="OK name="b1"> <animation source="trailer.avi"> 1 < 2 < 3 </click-button> < / xml >

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

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

LINQ to XML

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, …)

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

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); }

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") ) );

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

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

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 – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

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