Podcast
Questions and Answers
Which characteristic distinguishes XML from HTML?
Which characteristic distinguishes XML from HTML?
- HTML is about displaying information, while XML focuses on describing information. (correct)
- XML is an inconsistent standard, whereas HTML requires all tags to be closed.
- XML defines the valid tags and structure for web pages, while HTML is used to mark up text.
- HTML is a meta-language used to define other languages, while XML itself has predefined tags.
Why is XML considered a cross-platform, software, and hardware-independent tool?
Why is XML considered a cross-platform, software, and hardware-independent tool?
- It can be used to display information on web pages.
- It provides a standardized way to transmit information and data. (correct)
- It requires specific software to run.
- It is only compatible with specific operating systems.
In XML, what purpose do namespaces serve?
In XML, what purpose do namespaces serve?
- To display information in a standardized format.
- To avoid naming conflicts when using the same element name for different things. (correct)
- To act as a language used to define other languages.
- To define the valid tags and structure for web pages.
Considering an XML document representing course information, which element would be considered the 'root' element?
Considering an XML document representing course information, which element would be considered the 'root' element?
What does it mean for an XML file to be 'valid'?
What does it mean for an XML file to be 'valid'?
In the context of XML, what is the primary function of XSLT (extensible stylesheet language transformations)?
In the context of XML, what is the primary function of XSLT (extensible stylesheet language transformations)?
In XML, what does an XML Schema Definition (XSD) primarily define?
In XML, what does an XML Schema Definition (XSD) primarily define?
When considering the choice between XML and binary formats for data transfer, what is an advantage of using binary formats?
When considering the choice between XML and binary formats for data transfer, what is an advantage of using binary formats?
How does XML contribute to interoperability in data exchange?
How does XML contribute to interoperability in data exchange?
In the context of data serialization, what is the primary goal?
In the context of data serialization, what is the primary goal?
What is the main advantage of using XML for data transmission, particularly in scenarios requiring self-describing messages?
What is the main advantage of using XML for data transmission, particularly in scenarios requiring self-describing messages?
What is a primary distinction between XML and JSON concerning namespaces?
What is a primary distinction between XML and JSON concerning namespaces?
In terms of data types, how does JSON compare with XML?
In terms of data types, how does JSON compare with XML?
Which feature is notably lacking in JSON compared to XML?
Which feature is notably lacking in JSON compared to XML?
What does it imply when JSON is referred to as lightweight?
What does it imply when JSON is referred to as lightweight?
Which of the following best describes the syntax of a JSON object?
Which of the following best describes the syntax of a JSON object?
How are name/value pairs separated within a JSON object?
How are name/value pairs separated within a JSON object?
What is the primary purpose of the curly braces {}
in JSON syntax?
What is the primary purpose of the curly braces {}
in JSON syntax?
Which of the following is true regarding JSON arrays?
Which of the following is true regarding JSON arrays?
What is the proper way to define a string in JSON?
What is the proper way to define a string in JSON?
What value is used in JSON to represent 'nothing or no value'?
What value is used in JSON to represent 'nothing or no value'?
What could be a potential consideration when deciding to use JSON for configuration files, instead of YAML?
What could be a potential consideration when deciding to use JSON for configuration files, instead of YAML?
Which format is most suitable for transferring data to and from a server via asynchronous calls, without requiring a page refresh?
Which format is most suitable for transferring data to and from a server via asynchronous calls, without requiring a page refresh?
When is it appropriate to use JSON in web development?
When is it appropriate to use JSON in web development?
What is the main concept of JSON in the context of data?
What is the main concept of JSON in the context of data?
Which of the following could be a disadvantage of using XML format over JSON format?
Which of the following could be a disadvantage of using XML format over JSON format?
What does the term well-formed mean in the context of XML documents?
What does the term well-formed mean in the context of XML documents?
What are the key factors that determine the use-case of binary data formats in network protocols?
What are the key factors that determine the use-case of binary data formats in network protocols?
Which of the following technologies is used to format XML documents?
Which of the following technologies is used to format XML documents?
What is the role of XML in defining a format for data transmission over the internet?
What is the role of XML in defining a format for data transmission over the internet?
Which statement accurately reflects a key distinction between XML and JSON?
Which statement accurately reflects a key distinction between XML and JSON?
During data transmission, what is the purpose of serialization?
During data transmission, what is the purpose of serialization?
When defining elements and attributes in XML, which of the following is true?
When defining elements and attributes in XML, which of the following is true?
What must all XML values, including numbers, be enclosed in?
What must all XML values, including numbers, be enclosed in?
What is the purpose of the elementFormDefault="qualified"
attribute in an XML schema?
What is the purpose of the elementFormDefault="qualified"
attribute in an XML schema?
Consider this snippet:
<book xmlns="http://www.bookstuff.org/bookinfo">
<title>All About XML</title>
<author>Joe Developer</author>
<publisher xmlns="urn:publishers:publinfo">
<name>Microsoft Press</name>
</publisher>
</book>
Which elements belong to the http://www.bookstuff.org/bookinfo
namespace?
Consider this snippet:
<book xmlns="http://www.bookstuff.org/bookinfo">
<title>All About XML</title>
<author>Joe Developer</author>
<publisher xmlns="urn:publishers:publinfo">
<name>Microsoft Press</name>
</publisher>
</book>
Which elements belong to the http://www.bookstuff.org/bookinfo
namespace?
What is the primary indicator that an XSD element uses data types and elements from the XMLSchema, requiring a prefix?
What is the primary indicator that an XSD element uses data types and elements from the XMLSchema, requiring a prefix?
For which use case is JSON particularly well-suited?
For which use case is JSON particularly well-suited?
What syntax is necessary when creating a JSON document?
What syntax is necessary when creating a JSON document?
Flashcards
What is XML?
What is XML?
Stands for eXtensible Markup Language. It is used to structure, store, and transport data.
What is Marked-up text?
What is Marked-up text?
Text that is structured with textual tags providing meaning to the contents.
XML vs. HTML
XML vs. HTML
Unlike HTML that is about displaying information, XML focuses on describing it. It is also self describing and platform neutral
What is a Meta Language?
What is a Meta Language?
Signup and view all the flashcards
Why use XML?
Why use XML?
Signup and view all the flashcards
What is a root element?
What is a root element?
Signup and view all the flashcards
What are XML elements (or tags)?
What are XML elements (or tags)?
Signup and view all the flashcards
What are XML Attributes?
What are XML Attributes?
Signup and view all the flashcards
What are benefits of XML?
What are benefits of XML?
Signup and view all the flashcards
What is XML Schema?
What is XML Schema?
Signup and view all the flashcards
What are XML Namespaces?
What are XML Namespaces?
Signup and view all the flashcards
What is Default Namespace?
What is Default Namespace?
Signup and view all the flashcards
What is XSLT?
What is XSLT?
Signup and view all the flashcards
What is Binary data format?
What is Binary data format?
Signup and view all the flashcards
What is Text data format?
What is Text data format?
Signup and view all the flashcards
What is Serialization?
What is Serialization?
Signup and view all the flashcards
What is Deserialization?
What is Deserialization?
Signup and view all the flashcards
What is JSON?
What is JSON?
Signup and view all the flashcards
JSON Object Syntax
JSON Object Syntax
Signup and view all the flashcards
When is JSON is Used?
When is JSON is Used?
Signup and view all the flashcards
Study Notes
Lecture 7 – Open Message Formats
- Covers XML and JSON for network object transfer via serialization.
- Focuses on XML and JSON since they are message formats widely used in RPC methods for data transfer.
What is XML?
- XML is the eXtensible Markup Language.
- It structures text by encasing it with textual tags, describing the meaning of text content.
- The markup language defines valid tags and structure without dictating their use.
Use of ASCII vs XML
-
ASCII can store data for retrieval across platforms, however, the meaning is not clear. An example is "10, Nimal, 56"
-
XML is self-describing and platform-neutral, like:
10 Nimal 56
XML vs. HTML
- HTML defines valid tags and structure for web pages.
- HTML has a Fairly inconsistent standard; tags don't always need closing (e.g.,
<p>
). - XML can be used to mark up text
- It's a Meta Language: a language used to define other languages.
- XML itself has no tags: XML tags are not predefined, requiring you to 'invent' your own tags for a new language.
- HTML is about displaying information, while XML is about describing information.
Why Use XML?
- XML is a markup language for documents with structured data
- It describes data in human-readable, structured form.
- Structured information can contain both content, as well as information that defines the content.
- It's a cross-platform, software, and hardware-independent tool for transmitting information/data.
Where To Use XML
- XML finds its use in e-commerce (B2B), content management, web services, distributed computing, peer-to-peer (P2P), and the Semantic Web.
- However, it can need a lot of space
- 3-20 times larger compared to binary format.
- XML plays a role for the future of the Web, similar to HTML.
- It's a common tool for data manipulation and data transmission.
XML as a Universal Language
- XML is a "use everywhere" data specification.
XML Document Sample
- XML doc:
courselist
course
lecturer
first name
last name
title
code
Benefits of XML
- XML follows an Open W3C standard
- Data is represented across heterogeneous environments
- Supports cross-platform use
- High degree of interoperability
- XML dictates strict rules
- Syntax
- Structure
- Case sensitivity
XML Syntax Composition
- An XML declaration (e.g.,
<?xml version = "1.0" encoding="ISO-8859-1"?>
) is included though optional - There should be identification of the XML version, namespace, and encoding schema to which the document conforms
- XML also contains Markup types
- Elements (and attributes)
- Entity references
- Comments (
<!-- what ever you want to say -->
) - Processing instructions (
<?instruction options?>
)
- Content
Elements and Attributes
- Elements are tags
- e.g.
<course> </course>
- e.g.
- Attributes are
<course level = "undergraduate">
- Attributes provide information about an element
- An attribute value is required, optional, or fixed, with a default value possible.
- Attributes can often be replaced by nested elements.
- All values must be quoted, even for numbers, as in XHTML.
Element and Attribute Naming
- Elements and attributes can be named in nearly any manner.
- These are descriptive and not confusing with no length limit
- Are case sensitive, and can use the underscore (_).
- No names are reserved for XML; namespaces resolve naming conflicts.
- Names cannot start with a number, reserved punctuation, "XML" or "Xml".
- Contain not spaces, colons (:), greater-than (>), or less-than (<)
- Best practice to not use the hyphen (-) or period (.)
XML root element
- Each element (lecturer, title, and code) is rooted in “course”
- Each element (lecturer, title, and code) are children
XML Content
- The text lies within elements
- This is how documents are structured
- Content may consist of any data as long as it does not get confused with XML metadata
- Use Instructions use entity references for special characters!
- Each XML document must have one root element
Well-Formed XML
- XML must be formatted correctly
- All tags must be closed
XML Namespaces
- XML tags are user defined.
- Elements with the name can lead to naming confllicts
- XML applications use XML-based languages defined by various parties may have same element names.
- Online furniture is good example. Vendors might have similar tables
- To tackle table issues, use namespaces
XML namespace naming
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
- There will be no conflict because elements have different names
XML Namespace Properties
- To use XML prefixes, a namespace must for the prefix itself must be defined
- This is defined by the
xmlns
attribute in the start tag - This has the following syntax:
xmlns:prefix="URI"
. - Each namespace is identified by a URI.
Namespaces: Declaration examples
xmlns: bk = "http://www.example.com/bookinfo/"
xmlns: bk = "urn:mybookstuff.org:bookinfo"
xmlns: bk = "http://www.example.com/bookinfo/"
Multiple XML Namespace
<furniture xmlns = "http://www.itee.uq.edu.au/~zxf/furniture"
xmlns:ikea = "http://www.ikea.com/names"
xmlns:html="http://www.w3.org/TR_REC-html40">
- The code above shows the element can have 3 namespaces
- One default, others for IKEA and HTML
Default and Scope
<BOOK xmlns="www.bookstuff.org/bookinfo">
<TITLE>All About XML</TITLE>
<AUTHOR>Joe Developer</AUTHOR>
<PUBLISHER xmlns="urn:publishers:publinfo">
<NAME>Microsoft Press</NAME>
</PUBLISHER>
</BOOK>
- An XML namespace without a prefix becomes the default for sub-elements
- Elements without a prefix are part of the default namespace
- Unqualified elements belong to the inner-most default namespace
- In the example BOOK, TITLE, and AUTHOR are part of book’s namespace
- However, PUBLISHER and NAME fall under the publisher namespace
Sample XML document with two namespaces
<courselist xmlns:c="http://www.university.com/courses"
xmlns:l="http://www.university.com/lecturers">
<c:course id="001">
<c:name>SPDII</c:name>
<l:lecturers>
<l:lecturer>
<l:fname>Sheron</l:fname>
<l.Iname>Dinushka</I.Iname>
</l:lecturer>
<l:lecturer>
<l:name>Nishani</l:name>
<l:Iname>Ranpatabandi</l:Iname>
</l:lecturer>
</l:lecturers>
</c:course>
</courselist>
XML Schema (XSD)
- XML Schema Definition language
- Description of the structure of an XML document
- XSD is an XML file following a fixed standard
- It Replaces the less-flexible DTD (Document Type Definition)
- Parsers use XD to check XML files; this is for validation as opposed to using well-formed structures:
- With well-formed schemas: the general XML syntax rules are followed
- e.g. Tags have end-tags, nesting is correct
- Validity: The document follows XSD’s semantics
- e.g. the tags/attributes used are defined in XSD, which means the structure is OK
- With well-formed schemas: the general XML syntax rules are followed
What does XXSD Define?
- Contains what elements can appear in a document
- Dictates what attributes can appear
- Which elements are children
- Order of children
- How many children
- If the element can be empty, or include text
- What elements are to have default and fixed values
Note.xml Example
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com/note"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XSD for Note.xml Sample
<?xml version="1.0"?>
<xs:schema xmlns:xs= "http://www.w3.org/2001/XMLSchema""
targetNamespace=“http://www.w3schools.com/note”
xmlns="http://www.w3schools.com"
elementFormDefault= "qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Schema Element
- The element is the root for every XML Schema.
- The element can have attributes.
-This states that the elements and data types are from “http://www.w3.org/2001/XMLSchema", which should be prefixed with xsxmlns:xs= http://www.w3.org/2001/XMLSchema
More on element
targetNamespace="http://www.w3schools.com/note"
- This states that the elements defined by the schema (note, to, from, heading, body.) are assigned to the target namespace.
xmlns=http://www.w3schools.com
- States the defualt namespace
elementFormDefault="qualified"
- Elements used by the XML instance document must be namespace qualified if declared in this schema
Referencing XSD
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://www.w3schools.com note.xsd">
- This can be used to link the XML docs with the schemaLocation attribute
- Since the schemaLocation attribute is in the "http://www.w3.org/2001/XMLSchema-instance"" namespace, this MUST be declared and it MUST be mapped to
xsi
as a prefix
Complex Types in XSD
- A complex element is an XML element that contains other elements and/or attributes.
- Example
John
Smith
- The "employee" element can be declared directly by naming the element, like this:
""/>
Simple elements in XSD
- Element has this syntax:
<xs:element name="xxx" type="yyy"/>
- xxx is for element name, yyy is for type
- XML has an array of built-in types, including:
- string
- decimal
- integer
- boolean
- date
- time
Defining data types example:
Smith
36
1970-03-27
- Corresponding simple element definitions:
type="xs:string"/>
type="xs:integer"/>
type="xs:date"/>
Attributes in XSD
- Has this syntax:
<xs:attribute name="xxx" type="yyy"/>
- xxx to attribute name, and yyy to specify data type
- Simple elements DO NOT have attributes!
Attribute example
Smith
Structuring Data with XML for Stocks Example
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href=”StockPortfolio.css"?>
<StockPortfolio xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
xsi:schemaLocation="http://www.cs.curtin.edu.au/spd361
StockPortfolio.xsd">
<Stocks>
<StockPurchase>
<Ticker>GOOG</Ticker>
<PurchasePrice>330.06</PurchasePrice>
<NumPurchased>30</NumPurchased>
</StockPurchase>
<StockPurchase>
<Ticker>MSFT</Ticker>
<PurchasePrice>17.21</PurchasePrice>
<NumPurchased>580</NumPurchased>
</StockPurchase>
</Stocks>
</StockPortfolio >
Stock with XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="StockPortfolio">
<xs:complexType>
<xs:sequence>
<xs:element name="Stocks"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Stocks">
<xs:complexType>
<xs:sequence>
<xs:element name="StockPurchase" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
More on Stock with XML Schema
<xs:element name="StockPurchase">
<xs:complexType>
<xs:sequence>
<xs:element name="Ticker"/>
<xs:element name="PurchasePrice"/>
<xs:element name="NumPurchased"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Ticker" type="xs:string"/>
<xs:element name="NumPurchased" type="xs:int"/>
<xs:element name="PurchasePrice" type="xs:double"/>
</xs:schema>
Exercise: Write the XSD for the following XML
<?xml version = "1.0" encoding="ISO-8859-1"?>
<courselist>
<course>
<lecturer>
<firstname> H.T. </firstname>
<lastname> Shen </lastname>
</lecturer>
<title>SOA</title>
<code>INFS3204</code>
</course>
</courselist>
Automating XSD Creation
- Although this example was created by hand
- Tools existing make is automatic now
- .NET: xsd.exe
- Java: JAXB (Java Architecture for XML Binding) xjc.exe
Displaying XML
- Displaying XML will require XSLT (extensible stylesheet language transformations)
- Which is used to format XML documents
- XML contains the content
- XSLT contains the formatting
- XML + XSLT = HTML
Text vs Binary Formats
- "binary” format means the data concepts get mapped to the native Entities for the computer system; that means bytes
- With the “text” format, the data concepts get mapped to characters which must be translated from or to computer entities
- Strings can be needed for arithmetic
XML vs Binary
XML | Binary |
---|---|
‘Human readable’ | Requires software interpretation |
Single, Universal Standard
|
Many binary formats, availability varies |
Stored as a stream of Unicode, in a single file
|
Many organizations
|
XML Advantages Over Binary
- XML is self describing and also platform neutral
Binary Advantages Over XML
- Size: Smaller data size, minimal overhead size (ie: no tags)
- Speed: No need to convert between text and numeric data
- Simpler: Parsing XML is a complicated exercise
- And XML can be too flexible: multiple ways to do same thing
Why Text Over Binary
- Encoded well for the network. Protocols such as data transfer are traditionally binary
- Java is an example
- XML formats data transmission entirely in text: XML tags
- Such as SOAP. Basis for web services
What is Serialization?
- Serialization is converting and encoding an object into a data stream
- This includes aggregated or contained objects
- Used for disk saving, or transfer over a network
- Deserialization in conversion back from disk
- Types Binary XML (single textual conversion)
Overview of JSON
- What is JSON?
- How does it compare with XML?
- Discuss syntax
- All data types
- Usage
JSON is...
- A lightweight data-interchange, text-based format
- Language independent
- Based on Javascript, therefore easy to understand
JSON is Not...
- Overly Complex
- a “document” format
- a markup language
- a programming language
Why Use JSON
- Has straght foward syntax
- IsEasy to create and manipulate
- Can be parsed by JS eval() function
- Supported by most JS frameworks
Does JSON compare with XML?
-
JSON and XML have similaries
-
Both are hierachical and good for data
-
JSON is lighter and faster
-
Unlike XML, JSON doesn't have
- Namespaces
- Inherit validation
JSON Object Syntax
- These are unordered
- Have name/value pairs
- Follow these syntax requirements
- Begins with { (left brace)
- Ends with } (right brace)
- Each name is followed by : (colon)
- Name/value pairs are separated by , (comma)
JSON Example:
var employeeData = {
"employee_id": 1234567,
"name": "Jeff Fox",
"hire_date": "1/1/2013",
"location": "Norwalk, CT",
"consultant": false
};
Arrays in JSON
- Ordered collections of values.
- Begins with [ (left bracket)
- Ends with ] (right bracket).
- Name/value pairs are separated by , (comma)
Boaleans and NULL
- A boolean is either true or false
- NuLL is something that doesn't represent a value
Types of Data Objects and Arrays
- Objects: Unordered key/value pairs wrapped in { }
- Arrays: Ordered key/value pairs wrapped in [ ]
- You can nest objects (for supporting complex object)
Open Data Formats
- YAML is an example of open data, or markup languages
- Has these links to know more
https://blog.stackpath.com/yaml/
https://octopus.com/blog/state-of-config-file-formats
- Often used to define REST APIs. Defines component/service interfaces and key usage.
Data Formats: Summary
- Binary data formats are efficient to send and receive messages
- However due TEXT datatypes, they are more open
- XML therefore had richer features
- However:
- JSON is more lightweight
- "You can also use YAML
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.