Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML and JSON 1. XML, a very brief introduction XML = eXtensible Markup Language Language to describe data to be exchanged on the web And many other things.

Similar presentations


Presentation on theme: "XML and JSON 1. XML, a very brief introduction XML = eXtensible Markup Language Language to describe data to be exchanged on the web And many other things."— Presentation transcript:

1 XML and JSON 1

2 XML, a very brief introduction XML = eXtensible Markup Language Language to describe data to be exchanged on the web And many other things Program exchange XML documents XML documents are processed by programs Mark up language XML tags structure information Element …. An element may have many sub-elements Nested elements An element has exactly 1 super-element Except the root element, which has 0 super- elements Example XML document Anders Roskilde Michael Valby XML and JSON2

3 Structure in XML documents Well-formed All start-tags must have a matching end-tag … Tags must be properly nested … Only 1 outer tag Called the root element Valid Well-formed Conforms to an XML schema A set of “grammar rules” Specifies which tags are allowed, etc. XML and JSON3

4 XML serialization A C# object can be serialized into an XML document. The state of the object is made into an XML document Class XmlSerializer Example: XmlSerialization An XML object can be de-serialized into a C# object Create new object using default constructor Use set part of properties to set the state of the object Example: XmlSerialization XML and JSON4

5 XPath XPath is a language for finding information in an XML document. With Xpath you can extract the information you need from an XML document Examples http://www.w3schools.com/xml/xml_xpath.asp xpathExamples, using class XmlDocument XML and JSON5

6 JSON JSON = JavaScript Object Notation Language for storing and exchanging data Structure { object } “name” : “value” “name” : [“value1”, “value2”] Examples http://www.w3schools.com/json/json_syntax.asp XML and JSON6

7 XML serialization A C# object can be serialized into a JSON string The state on the object is serialized A JSON string can be de-serialized into a C# object Create new object using default constructor Use set part of properties to set the state of the object API C# has some … Most C# programmers use JSON.NET from NewtonSoft http://www.newtonsoft.com/json NuGet this package into your Visual Studio solution Examples jsonSerialization XML and JSON7

8 XML vs. JSON JSON is simpler than XML JSON string are shorter than XML documents Use less disk / network bandwidth XML came first, then JSON XML and JSON8


Download ppt "XML and JSON 1. XML, a very brief introduction XML = eXtensible Markup Language Language to describe data to be exchanged on the web And many other things."

Similar presentations


Ads by Google