Basic XML Concepts, Schemas, XPath, XSL Learning & Development Team Telerik Software Academy.

Slides:



Advertisements
Similar presentations
Windows Basic and Dynamic Disk Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Advertisements

HTML Forms, GET, POST Methods Tran Anh Tuan Edit from Telerik Academy
Amazon S 3, App Engine Blobstore, Google Cloud Storage, Azure Blobs Svetlin Nakov Telerik Software Academy academy.telerik.com.
RPN and Shunting-yard algorithm Ivaylo Kenov Telerik Software Academy academy.telerik.com Technical Assistant
Shortest paths in edge-weighted digraph Krasin Georgiev Technical University of Sofia g.krasin at gmail com Assistant Professor.
Telerik Software Academy Telerik School Academy.
Asynchronous Programming with C# and WinRT
Unleash the Power of JavaScript Tooling Telerik Software Academy End-to-end JavaScript Applications.
Telerik School Academy ASP.NET MVC.
Character sequences, C-strings and the C++ String class, Working with Strings Learning & Development Team Telerik Software Academy.
Hybrid or Native?! Doncho Minkov Telerik Software Academy Senior Technical Trainer
Done already for your convenience! Telerik School Academy Unity 2D Game Development.
Processing Sequences of Elements Telerik School Academy C# Fundamentals – Part 1.
C# Fundamentals – Part I
NoSQL Concepts, Redis, MongoDB, CouchDB
Telerik Software Academy Telerik School Academy Creating E/R Diagrams with SQL Server.
The Business Plan and the Business Model Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System Analyst Telerik Corporation.
What are ADTs, STL Intro, vector, list, queue, stack Learning & Development Team Telerik Software Academy.
Making JavaScript code by template! Learning & Development Team Telerik Software Academy.
Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training Who, What, Why?
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Processing Matrices and Multidimensional Tables Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Learning & Development Telerik Software Academy.
Reading and Writing Text Files Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Telerik Software Academy ASP.NET Web Forms.
Classical OOP in JavaScript Classes and stuff Telerik Software Academy
Svetlin Nakov Telerik Software Academy Manager Technical Training DOM Parser, Streaming Parser, XPath, LINQ to.
Optimization problems, Greedy Algorithms, Optimal Substructure and Greedy choice Learning & Development Team Telerik Software.
Using Selenium for Mobile Web Testing Powered by KendoUI Telerik QA Academy Atanas Georgiev Senior QA Engineer KendoUI Team.
NoSQL Concepts, Redis, MongoDB, CouchDB Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
New features: classes, generators, iterators, etc. Telerik Academy Plus JavaScript.Next.
Creating E/R Diagrams with SQL Server Management Studio and MySQL Workbench Svetlin Nakov Telerik Software Academy Manager Technical.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
Loops, Conditional Statements, Functions Tran Anh Tuan Edit from Telerik Academy
Private/Public fields, Module, Revealing Module Learning & Development Team Telerik Software Academy.
Building Data-Driven ASP.NET Web Forms Apps Telerik Software Academy ASP.NET Web Forms.
Course Introduction Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Telerik Software Academy End-to-end JavaScript Applications.
General and reusable solutions to common problems in software design Vasil Dininski Telerik Software Academy academy.telerik.com Intern at Telerik Academy.
Planning and Tracking Software Quality Yordan Dimitrov Telerik Corporation Team Leader, Team Pulse, Team Leader, Team Pulse, Telerik Corporation,
What you need to know Ivaylo Kenov Telerik Corporation Telerik Academy Student.
Data binding concepts, Bindings in WinJS George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Pavel Kolev Telerik Software Academy Senior.Net Developer and Trainer
Objects, Properties, Primitive and Reference Types Learning & Development Team Telerik Software Academy.
When and How to Refactor? Refactoring Patterns Alexander Vakrilov Telerik Corporation Senior Developer and Team Leader.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Doing the Canvas the "easy way"! Learning & Development Telerik Software Academy.
The past, the present, the future Telerik School Academy HTML, CSS and JavaScript.
Doncho Minkov Telerik Software Academy academy.telerik.com Technical Trainer Next Generation for Desktop Applications.
Creating and Running Your First C# Program Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Course Overview Doncho Minkov Telerik Software Academy Technical Trainer
Data Types, Primitive Types in C++, Variables – Declaration, Initialization, Scope Telerik Software Academy academy.telerik.com Learning and Development.
The past, the present, the future Learning & Development Team Telerik Software Academy.
Connecting, Queries, Best Practices Tran Anh Tuan Edit from Telerik Software Academy
Processing Sequences of Elements Telerik Software Academy C# Fundamentals – Part 2.
Telerik JavaScript Framework Telerik Software Academy Hybrid Mobile Applications.
Building Rock-Solid Software Nikolay Kostov Telerik Software Academy academy.telerik.com Senior Software Developer and Technical Trainer
Telerik Software Academy Databases.
Things start to get serious Telerik Software Academy JavaScript OOP.
Learning & Development Mobile apps for iPhone & iPad.
Processing Matrices and Multidimensional Tables Telerik Software Academy C# Fundamentals – Part 2.
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Functions and Function Expressions Closures, Function Scope, Nested Functions Telerik Software Academy
Implementing Control Logic in C# Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical trainer
Mocking tools for easier unit testing Telerik Software Academy High Quality Code.
What why and how? Telerik School Academy Unity 2D Game Development.
Windows Security Model Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
XML Processing SoftUni Team Database Applications Technical Trainers
Presentation transcript:

Basic XML Concepts, Schemas, XPath, XSL Learning & Development Team Telerik Software Academy

1. What is XML? 2. XML and HTML 3. When to use XML? 4. Namespaces 5. Schemas and validation  DTD and XSD Schemas 6. XML Parsers 7. XPath Language 8. XSL Transformations 2

 XML (eXtensible Markup Language)  Universal language (notation) 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  XML looks like HTML  Text based language, uses tags and attributes 4

 Worldwide standard, supported by the W3C (  Independent of the hardware platform, OS and programming languages 5

6 Professional C# 4.0 and.NET 4 Professional C# 4.0 and.NET 4 Christian Nagel Christian Nagel Silverlight in Action Silverlight in Action Pete Brown Pete Brown </library>

7 Professional C# 4.0 and.NET 4 Professional C# 4.0 and.NET 4 Christian Nagel Christian Nagel Silverlight in Action Silverlight in Action Pete Brown Pete Brown </library> Attribute (key / value pair) Opening tag XML header tag (prolog) Root (document) element Element Closing tag Element value

 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  HTML describes the formatting of information, XML describes structured information  XML requires the documents to be well-formatted 8

 Well-formatted XML:  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 9

 Example of incorrect XML document  Open / close tags do not match  Unclosed attribute values  Invalid characters  … < 2 < 3

 Advantages of XML:  XML is human readable (unlike binary formats)  Any kind of structured data can be stored  Data comes with self-describing meta-data  Custom XML-based languages can be developed for certain applications  Information can be exchanged between different systems with ease  Unicode is fully supported 11

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

 XML namespaces are defined like this: 14 <sample:towns xmlns:sample=" xmlns:sample=" Sofia Sofia Plovdiv Plovdiv </sample:towns>

 Namespaces in XML documents allow using different tags with the same name: 15 <country:towns xmlns:country="urn:academy-com:country" xmlns:country="urn:academy-com:country" xmlns:town=" xmlns:town=" Plovdiv Plovdiv Bulgaria Bulgaria </country:towns>

16 <country:towns xmlns:country="urn:academy-com:country" xmlns:town=" xmlns:town=" Sofia Sofia Bulgaria Bulgaria Plovdiv Plovdiv Bulgaria Bulgaria </country:towns> Namespace with prefix "country" and URI "urn:academy-com:country" Tag named "name" from namespace "country"  the full tag name is "urn:academy-com:country:name"

 Default namespaces can save some code: 17 Beer "Zagorka" Beer "Zagorka" 8 8 bottle bottle Meat balls Meat balls amount amount </order> Default namespace – applied for the entire XML document

 The XML documents structure is defined by schemas  XML schemas describes:  Possible attributes and tags and their values  Tags order  Default values and number of appearances  There are few XML Schema standards:  DTD – Document Type Definition  XSD – XML Schema Definition Language 19

 DTD (Document Type Definition) is:  Formal language for describing XML document structures  Contains a set of rules for the tags and their attributes in a document  Text-based language, but not XML based  Substituted by XSD (relatively rarely used) 20

 XSD (XML Schema Definition Language)  Powerful XML-based language for describing the structure of XML documents  Contains a set of rules for the tags and their attributes in a document  Specifies few standard data types  Numbers, dates, strings, etc.  XSD Schemas have greater descriptive power than DTD 21

22 <xs:schema xmlns:xs=" targetNamespace=" <xs:element ref="book" <xs:element ref="book" maxOccurs="unbounded"/> maxOccurs="unbounded"/> <xs:attribute name="name" <xs:attribute name="name" type="xs:string" use="optional"/> type="xs:string" use="optional"/>

23 </xs:schema>

24 Professional C# 4.0 and.NET 4 Professional C# 4.0 and.NET 4 Christian Nagel Christian Nagel Professional C# 4.0 and.NET 4 Professional C# 4.0 and.NET 4 Christian Nagel Christian Nagel

 Visual Studio can generate XSD Schemas from the structure of a given XML document  VS has powerful XSD Schema Editor  Visually edit schemas 25

Live Demo

 XML parsers are programming libraries that make the work with XML easier  They serve for:  Extracting data from XML documents  Modifying existing XML documents  Building new XML documents  Validating XML documents by given schema  Transforming XML documents 28

 They have several working models:  DOM (Document Object Model)  Represents XML documents as a tree in the memory  Allows processing and modifying the document  SAX (Simple API for XML Processing)  Reads XML documents consequently tag by tag  Event-driven API  Allows analyzing the read portions at each step  StAX (Streaming API for XML)  Like SAX but works in "pull" mode 29

 Given the following XML document: 30 Professional C# 4.0 and.NET 4 Professional C# 4.0 and.NET 4 Christian Nagel Christian Nagel Silverlight in Action Silverlight in Action Pete Brown Pete Brown </library>

 This document is represented in the in the memory as a DOM tree in the following way: 31 Header part (prolog) Root node

 The SAX parsers:  Iterate the document consequently tag by tag  Invoke callback functions (events) when particular node is reached  Stream-like access – going backwards or jumping ahead is not allowed  Require many times less resources (memory and loading time)  Work well over streams 32

 StAX is like SAX but  "Pull"-based parser  Not event driven (not callback based)  Developer manually say "go to next element" and analyze it  SAX vs. StAX  SAX reads the documents and invokes callbacks like "node found", "attribute found", etc.  In StAX parsers the read is invoked by the developer synchronously

 Use DOM processing model when:  Process not big documents (e.g. less than 10 MB)  There is a need of flexibility  To modify XML documents  Use SAX / StAX processing model when:  Process big documents  The performance is important  There is no need to change the document 34

 XPath (XML Path Language) is a language for addressing parts of XML documents  XPath expressions contains description of paths to nodes and filter criteria  Example for XPath expressions: 36 /library/book[isbn=' '] /book/chapter[3]/paragraph[last()]

 / – addresses the root element derived  /someNode – addresses all nodes with name " someNode ", straight inheritors to the root  /books/book – addresses all nodes " book ", straight inheritors to the node " books "  /books/book[price<10]/author – addresses all authors (/books/book/author), whose books have price < 10  – addresses all nodes with name item (/items/item/ ), which have attribute "type" with value "food" 37

 XSL transformations (XSLT) allows to  Transform of one XML document to other XML document with different structure  Convert between different XML formats  XSLT depends on XPath  XPath is used to match parts from the input document and replace them with another XML  In particular XSLT can be used for transforming XML documents to XHTML 39

40 <xsl:stylesheet version="1.0" xmlns:xsl=" xmlns:xsl=" My library My library Title Title Author Author </xsl:template></xsl:stylesheet>

 … – replaces the pointed with XPath expression part of the document with the construction body  … – replaces each node, pointed by the XPath expression with construction body  – extracts the value of the given XPath expression (the first occurrence)  XSL patterns are valid XML documents! 41

форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране

1. What does the XML language represents? What does it used for? 2. Create XML document students.xml, which contains structured description of students. For each student you should enter information for his name, sex, birth date, phone, , course, specialty, faculty number and a list of taken exams (exam name, tutor, score). 3. What does the namespaces represents in the XML documents? What are they used for? 43

4. Explore Uniform_Resource_Identifier to learn more about URI, URN and URL definitions. Uniform_Resource_Identifierhttp://en.wikipedia.org/wiki/ Uniform_Resource_Identifier 5. Add default namespace for the students " urn:students ". 6. Create XSD Schema for the students.xml document. Add new elements in the schema: information for enrollment (date and exam score) and teacher's endorsements. 7. Write a XSL stylesheet to visualize the students as HTML. Test it in your favourite browser. 44

 "Web Design with HTML 5, CSS 3 and JavaScript" Telerik Academy  html5course.telerik.com html5course.telerik.com  Telerik Software Academy  academy.telerik.com academy.telerik.com  Telerik Facebook  facebook.com/TelerikAcademy facebook.com/TelerikAcademy  Telerik Software Academy Forums  forums.academy.telerik.com forums.academy.telerik.com