Download XML basics

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
XML Basics
A brief introduction to XML in
general
XML Basics
1
What is XML?
• XML = eXtensible Markup Language
• XML vs. HTML
– XML was designed to store and transport data
– HTML was designed to display data
• XML is a W3C recommendation, 1998
XML Basics
2
Use of XML
• Storage
– XML documents can be stored on the hard disk
• In ordinary files or databases
• Sending information
– XML documents can be send between applications
– XML is just text
• Platform independence
• Language independence
• Some XML applications
– Web services
• WSDL: Web Service Description Language
• SOAP: Simple Object Access Protocol
– XHTML
• HTML described using XML
– RSS
• Really Simple Syndication
XML Basics
3
XML documents
• The first line in the document must be the XML declaration
– <?xml version="1.0" encoding="utf-8" ?>
• An XML document consists of XML elements
– <city>Roskilde</city>
– An element has a start tag and an end tag
• XML elements can have attributes
– Attribute values must be quoted ” ….”
– <student id=”14592> … </student>
• XML elements can contain
– Text
– Other XML elements
<student id=”14592>
<name>Anders</name>
<city>Roskilde</city>
</student>
• XML elements can be empty
– <book isbn=”1234” title=”XML stuff” />
• XML is case-sensitive
XML Basics
4
XML document, example
<?xml version="1.0" encoding="utf-8" ?>
<students>
<student id="14593">
<name>Anders</name>
<address>Roskilde</address>
</student>
<student id="1111">
<name>Bill</name>
<address>London</address>
</student>
</students>
XML Basics
5
Well formed
• XML documents should be well formed
–
–
–
–
–
–
–
–
it must begin with the XML declaration
it must have one unique root element
start-tags must have matching end-tags
elements are case sensitive
all elements must be closed
all elements must be properly nested
all attribute values must be quoted
entities must be used for special characters
• From http://www.w3schools.com/schema/schema_why.asp
XML Basics
6
XML name spaces
• Name conflict
– Different XML document may have elements with the same
name
• Element names can be prefixed to resolve name conflicts
– <prefix:tag> …. </prefix:tag>
• In XML a prefix must be declared using a name space
– <root
xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="http://www.w3schools.com/furniture"> … </root>
– Two namespaces, prefix h and f
• The namespace is an URI
– Uniform Resource Identifier
– It a unique name. Usually it does NOT lead to a web page!
– Default name space (no prefix)
• <table xmlns="http://www.w3.org/TR/html4/"> …</table>
XML Basics
7
XML support in Microsoft Visual Studio
• Writing XML documents
– Automatic indentation
– Marks (red line) if the document is not well
formed
XML Basics
8
XML support in browsers
• Most modern browsers can show XML
documents
– Since XML has no appearance, browsers show the
document as it is.
XML Basics
9
CSS formatting
• CSS = Cascading Style Sheets
• XML documents can be formatted using CSS
– http://www.w3schools.com/xml/xml_display.asp
• Formatting XML with CSS is not the most
common method.
• W3C does NOT recommend using CSS to style
XML documents
– W3C recommends using XSLT instead.
XML Basics
10
Related documents