Download presentation
Presentation is loading. Please wait.
Published byWilliam Long Modified over 9 years ago
1
ECA 228 Internet/Intranet Design I Intro to XML
2
ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard HTML disadvantages: – loose standards – fixed markup – maintenance
3
ECA 228 Internet/Intranet Design I XML markup language / meta language consists only of data and markup HTML was designed to display data and focus on how it looks. XML was designed to describe data, and focus on what it is. HTML is about displaying information. XML is about describing information.
4
ECA 228 Internet/Intranet Design I What is XML? XML – stands for EXtensible Markup Language – is a markup language much like HTML – was designed to describe data – tags are not predefined – you define your own tags – uses a DTD of XML Schema to describe the data – is designed to be self_descriptive
5
ECA 228 Internet/Intranet Design I HTML Example Bubba Jenna Reminder Remember, we’re looking for mushrooms tomorrow.
6
ECA 228 Internet/Intranet Design I XML Example Bubba Jenna Reminder We’re looking for mushrooms tomorrow. HTML is about displaying information. XML is about describing information.
7
ECA 228 Internet/Intranet Design I XML uses XML was designed to store, carry, and exchange data XML was not designed to display data in web pages – HTML to structure the document – CSS to add presentational elements – XML to provide content to exchange data between otherwise incompatible applications
8
ECA 228 Internet/Intranet Design I XML Example 1 st line is the XML declaration 2 nd line describes the root element next 4 lines are child elements of the root last line defines the end of the root element Bubba Jenna Reminder We’re looking for mushrooms tomorrow.
9
ECA 228 Internet/Intranet Design I XML Syntax All XML elements must have a closing tag – in HTML the following is legal – in XML it is illegal to omit the closing tag – empty tags must use opening/closing tag This is a paragraph.
10
ECA 228 Internet/Intranet Design I XML Syntax cont … XML tags are case sensitive This is incorrect This is correct
11
ECA 228 Internet/Intranet Design I XML Syntax cont … XML tags must be nested properly This is incorrect This is correct
12
ECA 228 Internet/Intranet Design I XML Syntax cont … XML documents must have a root element – root element contains all other elements – other elements may have child elements nested properly within them...
13
ECA 228 Internet/Intranet Design I XML Syntax cont … Attribute values must always be quoted – elements may contain attributes in name=value pairs Bubba Jenna Reminder We’re looking for mushrooms tomorrow.
14
ECA 228 Internet/Intranet Design I XML Syntax With XML, white space is preserved – HTML ignores all white space, but one renders as – XML preserves all white space Hi there, my name is Bubba.
15
ECA 228 Internet/Intranet Design I XML Syntax cont … XML converts CR / LF to LF – a new line is always stored as a LF ( line feed ) Windows apps store new lines as CR LF Unix apps store new lines as LF Mac apps store new lines as CR ( Carriage Return ) – XML converts all to LF
16
ECA 228 Internet/Intranet Design I XML Syntax cont … XML comments – XML comments are the same as in HTML
17
ECA 228 Internet/Intranet Design I XML Syntax cont … XML special symbols – to include an ampersand, a less than sign, or a greater than sign as data, use character entities CODE REPRESENTS &ersand <less than sign >greater than sign 'apostrophe "quote
18
ECA 228 Internet/Intranet Design I XML Elements XML elements can contain different types of content – element: contains other XML elements – text: contains only text – mixed: contains both text and other elements – empty: contains no content, such as the HTML tag
19
ECA 228 Internet/Intranet Design I Naming XML Elements Certain rules must be followed when naming elements – can contain letters, numbers, and some characters (underscore, hyphen, period, colon), however, caution should be used when using hyphen, period, or colon – must start with a letter, underscore, or colon (namespace), but no numbers – may not contain spaces – may not begin with the letters xml – is case sensitive
20
ECA 228 Internet/Intranet Design I Naming XML Elements cont … separate words are often separated by an underscore Caution when using a hyphen, period, or colon first_name first.name first-name
21
ECA 228 Internet/Intranet Design I Naming XML Elements cont … names can be as long as necessary keep names descriptive but simple XML document often has a corresponding database – element names may match filed names the_title_of_the_book book_title
22
ECA 228 Internet/Intranet Design I XML Attributes XML elements may contain attributes – attributes provide information which is not necessarily part of the data attributes are used in the opening tag of an element attribute values must always be quoted
23
ECA 228 Internet/Intranet Design I XML Attributes cont … if an attribute value contains double quotes, place single quotes around the value if an attribute uses single quotes or an apostrophe, place double quotes around the value
24
ECA 228 Internet/Intranet Design I XML Attributes cont … in many instances, attributes can be written as a child element Sophie’s Choice
25
ECA 228 Internet/Intranet Design I XML Attributes cont … if the information being provided by the attribute seems like data, use it as an element if the information clearly is not data, but can be used to classify or categorize the element, use an attribute 12/30/2003
26
ECA 228 Internet/Intranet Design I XML Attributes cont … meta data ( data about data ) should be stored as an attribute actual data should be stored as an element 30 12 2003
27
ECA 228 Internet/Intranet Design I Validation well-formed – a document that adheres to correct XML syntax valid – a document that is well-formed and conforms to a DTD DTD – Document Type Definition – defines a structure with a list of legal elements XML Schema – alternative to DTD
28
ECA 228 Internet/Intranet Design I Namespace combined XML documents risk name conflicts … …
29
ECA 228 Internet/Intranet Design I Namespace cont … create a prefix to distinguish similarly named elements … …
30
ECA 228 Internet/Intranet Design I Namespace cont … XML namespace – takes the form of a URL – based upon a unique domain name – namespace must have a unique & persistent name begin with domain name add descriptive information, as if it is a path in the URL http://www.justustwo.com/ns/tables
31
ECA 228 Internet/Intranet Design I Namespace cont … the URL does not necessarily point to a particular document a URL is used because it is unique a namespace must be declared before it can be used namespace declaration has a specific structure xmlns:namespace_prefix=“namespace_url”
32
ECA 228 Internet/Intranet Design I Namespace cont … prefix the xml elements with namespace name to declare a default namespace, omit the prefix … …
33
ECA 228 Internet/Intranet Design I Namespace cont … override a default namespace by specifying a prefix …
34
ECA 228 Internet/Intranet Design I Namespace cont … 3 reasons not to use the URL itself as a prefix 1. URL’s make use of the colon 2. very difficult to type and read 3. URL’s can contain special characters not permitted in XML … … …
35
ECA 228 Internet/Intranet Design I Formatting XML although it is possible to format XML with CSS, it is not recommended rather than CSS, the preferred way to format XML is with XSL ( EXtensible Stylesheet Language ) XSL can be used to transform XML into HTML before it is sent to the browser
36
ECA 228 Internet/Intranet Design I XML Data Island Microsoft proprietary technology not supported by the W3C specification XML Data Islands use an unofficial tagset Data Islands can embed XML directly into an HTML document
37
ECA 228 Internet/Intranet Design I XML Data Island cont … note that the tag is an HTML element, not an XML element Bubba Jenna Reminder Remember, we’re looking for mushrooms.
38
ECA 228 Internet/Intranet Design I XML Data Island cont … if the Data Island is a separate document, it can be embedded with a reference to the document
39
ECA 228 Internet/Intranet Design I Data Binding Microsoft proprietary technology not supported by the W3C Data Islands can be bound to HTML elements, such as an HTML table – load a Data Island from an external XML file – bind the table to the Data Island with a data source attribute ( datasrc ) – bind the table elements to the XML data with a data field attribute ( datafld ) inside a span tag, inside each table cell
40
ECA 228 Internet/Intranet Design I Data Binding note that the datafld matches the element name
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.