XML Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

Similar documents
Minimal Spanning Trees

The Critical-Path Algorithm

The Decreasing-Time Algorithm

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

XML and AJAX Lecture 28

DTDs and XML Attributes

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Form Validation. Lecture 25. Robb T. Koether. Hampden-Sydney College. Wed, Mar 23, 2018

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Sampling Distribution Examples Sections 15.4, 15.5

Rotations and Translations

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

jquery Lecture 34 Robb T. Koether Wed, Apr 10, 2013 Hampden-Sydney College Robb T. Koether (Hampden-Sydney College) jquery Wed, Apr 10, / 29

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Recursive Descent Parsers

XQuery FLOWR Expressions Lecture 35

The Graphics Pipeline

Scheduling and Digraphs

Density Curves Sections

The Pairwise-Comparison Method

The Traveling Salesman Problem Brute Force Method

Introduction to Databases

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

The Coefficient of Determination

Implementing Linked Lists

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Building the Abstract Syntax Trees

Solving Recursive Sequences by Iteration

LR Parsing - Conflicts

Scope and Parameter Passing

XQuery Constructors and Joins Lecture 36

AJAX. Lecture 26. Robb T. Koether. Fri, Mar 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) AJAX Fri, Mar 21, / 16

Function Definition Syntax Tree

Displaying Distributions - Quantitative Variables

Binary Tree Applications

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

The Class Construct Part 1

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

PHP Queries and HTML Forms Lecture 23

List Iterator Implementation

Magnification and Minification

The Graphics Pipeline

Scope and Parameter Passing

Street-Routing Problems

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Introduction to Databases

List Iterators. Lecture 34 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 24, 2013

Friends and Unary Operators

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

The Plurality-with-Elimination Method

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

The Projection Matrix

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

The CYK Parsing Algorithm

The Normal Distribution

Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

XSLT. Lecture 38. Robb T. Koether. Mon, Apr 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XSLT Mon, Apr 21, / 26

The Traveling Salesman Problem Cheapest-Link Algorithm

Introduction to Compiler Design

XML. Lecture 29. Robb T. Koether. Fri, Mar 28, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XML Fri, Mar 28, / 23

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

Nondeterministic Programming in C++

Recursive Linked Lists

Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

Basic PHP Lecture 17

Inheritance: The Fundamental Functions

Triggers. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 14, 2018

Recognition of Tokens

Basic CSS Lecture 17

Basic PHP. Lecture 19. Robb T. Koether. Hampden-Sydney College. Mon, Feb 26, 2108

Integer Overflow. Lecture 8 Section 2.5. Robb T. Koether. Hampden-Sydney College. Mon, Jan 27, 2014

Javascript Lecture 23

Ambient and Diffuse Light

Dynamic Allocation of Memory

Programming Languages

Programming Languages

Dynamic Allocation of Memory

Function Usage. Lecture 15 Sections 6.3, 6.4. Robb T. Koether. Hampden-Sydney College. Mon, Oct 1, 2018

The Model Stack. Lecture 8. Robb T. Koether. Hampden-Sydney College. Wed, Sep 6, 2017

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

Relational Databases Lecture 2

The x86 Instruction Set

Insertions, Deletions, and Updates

PHP Arrays. Lecture 18. Robb T. Koether. Hampden-Sydney College. Mon, Mar 4, 2013

Basic HTML. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 20, 2013

The Mesh Class. Lecture 26. Robb T. Koether. Wed, Oct 28, Hampden-Sydney College

Fundamental Data Types

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

Stacks and their Applications

Relational Databases

Transcription:

XML Attributes Lecture 33 Robb T. Koether Hampden-Sydney College Wed, Apr 25, 2018 Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 1 / 15

1 XML Attributes 2 The getattribute() Function 3 Attributes as References 4 Assignment Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 2 / 15

Outline 1 XML Attributes 2 The getattribute() Function 3 Attributes as References 4 Assignment Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 3 / 15

XML Attributes XML Attributes <tag_name attr-1="value-1" attr-2="value-2"...>. </tag_name> An XML element may be given any number of attributes. Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 4 / 15

XML Attributes XML Attributes <book lang="en" cover="hard"> <title>treasure Island</title> </book> The attributes are intended to provide information about the element, but not data itself. The distinction is not always clear. Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 5 / 15

Elements vs. Attributes When should we use elements and when should we use attributes? The W3Schools website makes the remark There are no rules about when to use attributes or when to use elements. Attributes are handy in HTML. In XML my advice is to avoid them. Use elements instead. They give three reasons: Attributes cannot contain multiple values (elements can) Attributes cannot contain tree structures (elements can) Attributes are not easily expandable (for future changes) I agree, except in the following examples. Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 6 / 15

XML Attributes XML Attributes var book_list = xml_doc.getelementsbytagname("book"); var attr_list = book_list[0].attributes; var attr = attr_list[0]; var attr_name = attr.nodename; var attr_value = attr.nodevalue; In Javascript, each element has the attributes property, which is an indexed list of the element s attributes. Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 7 / 15

Attributes as References See the example library-attr.xml and library-attr.html. The XML file uses reference IDs to associate authors with books. Thus, each author does not need to be listed more than once. (This example assumes that each book has only one author.) Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 8 / 15

Outline 1 XML Attributes 2 The getattribute() Function 3 Attributes as References 4 Assignment Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 9 / 15

The getattribute() Function The getattribute() Function var book_list = xml_doc.getelementsbytagname("book"); var attr = book_list[0].getattribute("lang"); var attr_name = attr.nodename; var attr_value = attr.nodevalue; We can use the getattribute() function to select a specific attribute. Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 10 / 15

Outline 1 XML Attributes 2 The getattribute() Function 3 Attributes as References 4 Assignment Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 11 / 15

Attributes as References Attributes as References <book authid="123">...</book> <author id="123"> <fname>mark</fname> <lname>twain</lname> </author> Attributes are often used to allow one element to refer to another element. This allows us to impose a structure on the XML file beyond the basic tree structure. Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 12 / 15

Attributes as References See the example library-attr2.xml and library-attr2.html. The XML file uses reference IDs to associate authors with books. Thus, each author does not need to be listed more than once. (This example assumes that each book has only one author.) Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 13 / 15

Outline 1 XML Attributes 2 The getattribute() Function 3 Attributes as References 4 Assignment Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 14 / 15

Assignment Assignment Visit the W3Schools website http://www.w3schools.com/xml/xml_attributes.asp Visit the section labeled XML Attributes. Robb T. Koether (Hampden-Sydney College) XML Attributes Wed, Apr 25, 2018 15 / 15