XML & XML Query Flashcards

1
Q

XML attribute vs subelement

A

Attribute-provides extra information about the element ex: [stuff]
Attributes are better for metadata about the element

sub-element ex: A-101
data about the element itself should be stored as subelements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When to attribute or subelement?

A

use attributes for identifiers

use sub-elements for contents of the element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the motivation for a xmlns?

A

the organization or context for which a given user-defined tag is from helps to determine its meaning.

Since tags are user-defined, different organizations may have tags of the same name with different meanings

The name of an organization is typically expressed with a unique URI (ex: http://www.FirstBank.com)

To avoid ambiguity each tag element could be specified by the following syntax: “”

Writing the unique URI along with every element on the page would quickly become tedious since they can get very long

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an XMLNS and what is the syntax?

A

an xmlns is a shortened name that represents the unique URI for an organization

ex: xmlns:FB=”http://www.FirstBank.com” Now every tag element in the belonging to this organization (or in the FB namespace) can be referenced as

(Be sure to remember the colon between the name of the namespace and the tag_name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

4 characteristics of an XML document (that I’m likely to forget)

A
  • element (or tag_names) themselves ARE NOT unique
  • within a given element, attribute name ARE unique
  • elements can be empty and expressed as follows
  • a “well-formed” XML follows a simple set of syntactic rules (doesn’t have any syntax errors)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does DTD stand for?

A

Document type definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the importance of XML schema?

A

Its important for the transfers of data.

It makes it possible for a site to interpret the XML data it receives from another site. Since each site can define its own tags a separate site needs some manner of interpreting the meaning of those tags

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

On a basic level, what is a DTD?

A

is a mechanism for specifying an XML schema

it defines the structure and the legal elements and attributes of an XML document

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The difference between a “well-formed” and “valid” XML document?

A

well-formed means syntactically correct, whereas valid means that it’s consistent with the DTD

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The 5 entities of an XML document as seen by a DTD

A
elements
attributes
entities
PCDATA
CDATA
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an XML entity?

A

Entities are used to define shortcuts to special characters.
Entities can be declared internal or external.

entities typically represent one of the following:

  • a character that has special meaning in the XML document
  • frequently repeated strings or characters
  • large blocks of text

These entities are replaced by whatever they represent (aka “expanded”) when parsed by an XML parser

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is PCDATA

A

parsed character data

This will be parsed by the XML parser

The parser will look through the PCDATA for entities and expand them and look for tag to treat as markup

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is CDATA

A

character data

this data WILL NOT be parsed by the XML parser

tags in here will not be treated as markup and entities will not be expanded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The basic syntax for declaring element in DTD?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the “category” in a DTD element declaration?

A

The “category” specifies what is expected to be found within the element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

6 different possibilities for the “category” or an DTD element declaration

A
EMPTY
#PCDATA/#CDATA
ANY
child elements
either/or content
mixed content
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does the “EMPTY” category in DTD element declaration mean? How is it expressed syntactically?

A

the element is expected to be empty (aka to have no contents inside)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What does the “#PCDATA/#CDATA” category in DTD element declaration mean? How is it expressed syntactically?

A

the element is expected to contain only parsed character data (for #PCDATA) or just character data (for #CDATA)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does the “ANY” category in DTD element declaration mean? How is it expressed syntactically?

A

the element is expected to contain any combination of parsable data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does the “child elements” category in DTD element declaration mean?

A

the element is expected to contain the named child elements as specified

Which child elements that are to be expected and the quantity of a given child element are expressed with particular syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How to syntactically express a DTD element with one child that will occur only once?

A
22
Q

How to syntactically express a DTD element with multiple chiuldren that will all only occur once?

A
23
Q

How to syntactically express a DTD element with children that occur ONE or more times?

A

or for multiple children

24
Q

How to syntactically express a DTD element with children that occur ZERO or more times?

A

or for multiple children

25
Q

How to syntactically express a DTD element with children that occur ZERO or ONE times (aka optional)?

A

or for multiple children

26
Q

What does the “either/or content” category in DTD element declaration mean? How is it expressed syntactically?

A

the element is expected to contain one of a given list of alternatives (can have as many alternatives as we want)

Means that the “element-name” is expected to contain one occurence of either “child_name1” or “child_name2”

Either/or content call also have occurrence specifications (think ANTLR)

ex: (child1 | child2)* = means that we can have zero to many children, and if their are children, each child must be a “child1” or a “child2”

27
Q

What does the “mixed content” category in DTD element declaration mean? How is it expressed syntactically?

A

the element is expected to possibly contain one of many kinds data

This means that “element-name” is expected to contain only PCDATA or one occurrence of “child1”

Just like with either/or content this mixed content can have occurrence specifications

This means that “element-name” is expected to contain one or more entries. Each entry should be parsed character data or a “child1” element

28
Q

What is an ATTLIST in the DTD? What is the general syntax for it?

A

specifies that attributes of a particular element

29
Q

What is the “attribute type” field for an ATTLIST declaration in DTD?

A

the attribute type specifies the type of attribute value the XML parser should expect

30
Q

What are the 9 supported attribute types

A
CDATA
(en1 | en2 | ...)
ID
IDREF
IDREFS
NMTOKEN
NMTOKENS
ENTITY
ENTITIES
NOTATION
31
Q

what is the “ID” attribute type?

A

it signals that the value is a unique id that identifies the given element (much like an HTML id)

32
Q

what is the “IDREF/IDREFS” attribute type?

A

IDREF signals that the value refers to the id of another element

IDREFS signals that the value is a list of ids (ids separated by whitespaces) to other elements

33
Q

what is the “NMTOKEN/NMTOKENS” attribute type?

A

NMTOKEN signals that the value is a valid XML name

A valid XML name is simply a string that does not contain whitespace, does not start with a number

NMTOKENS signals that the value is a list (XML names separated by whitespace) of valid XML names

34
Q

The 4 supported “attribute-value” types

A
value
#REQUIRED
#IMPLIED
#FIXED value
35
Q

What does the “value” attribute value mean? How is it expressed syntactically?

A

specifies the default value of an attribute if the user does not supply one

This means that the attribute named “cost” will be of type CDATA and that default value is “0”

Remember all attribute values are Strings!

36
Q

What does the “#REQUIRED” attribute value mean? How is it expressed syntactically?

A

specifies that the author must supply a value for a given attribute

Notice how a default value is not needed since the attribute is required

37
Q

What does the “#IMPLIED” attribute value mean? How is it expressed syntactically?

A

specifies that the attribute is optional. This typically implies that the attribute does not have a logical default value

In this case, there’s not a default phone_number that makes logical sense

38
Q

What does the “#FIXED value” attribute value mean? How is it expressed syntactically?

A

specifies that the element has an attribute with a fixed value that the author cannot change

An error will occur if the user attempts to change the value

39
Q

what is the Enumerated “(en1 | en2 ..)” attribute value?

A

when the attribute value is to be one of a fixed set of legal values

This says that the attribute payment can be either “card” or “cash” and that the default value is “cash” if the author does not specify the attribute

40
Q

What is the general syntax for declaring an internal ENTITY in DTD?

A
41
Q

What is the general syntax for declaring an external ENTITY in DTD?

A

The URl/URI references an external DTD where the specific entity is defined

42
Q

Syntax for using entity in XML

A

&entity_name;

the entity usage includes:

  • ampersand
  • entity_name
  • semicolon
43
Q

3 limitations of DTDs

A
  • no typing of elements and attributes. all values are strings
  • difficult to specify unordered sets of subelements
  • IDs and IDREFs are untyped
44
Q

What is an XPath node?

A

a node roughly speaking an element or attribute in the XML document

XPath views the document as a tree of nodes

Pro Tip: XML nodes contain XML elements, XML elements contain data or other elements

45
Q

6 ways to select nodes with XPath

A

“node_name” = select all nodes in the document with the name “node_name”

“/root_name” = selects the root element “root_name”

”//name” = selects all nodes of name = “name” no matter where they are in the document from within the current node

”//@lang” = select all attributes named “lang

”..” = select the parent of the current node

46
Q

Example XPath query

A

select all the titles
/bookstore/book/title

select the bookstore root element, from there select all the book root elements (that are children of bookstore), from within each of those select all the title elements that are children of the selected book elements

/bookstore//book/title

select from within bookstore ALL books (even those that are not direct children of bookstore) and then select all the titles which are children of those selected book elements

47
Q

Types XPath Predicates (examples)

A

all predicates are placed in square brackets [ ]

/bookstore/book[1] = get first book (indexing from `1 not zero) from within bookstore that is a child of bookstore

/bookstore/book[last()] = get last book from within book store that is a child of bookstore

/bookstore/book[last()] = get second to last child book from within bookstore

/bookstore/book[position()<3] = get all child books before the 3rd child book from within bookstore

/bookstore/book[price <35.00] = all child books from within bookstore with a price subelement that has a value less than 35

/bookstore/book[price <35.00]/title = get all child title elements of books that meet the above criteria

/bookstore/book[@lang] = get all child books from within bookstore with an attribute call “lang”

/bookstore/book[@lang=”en”] = get all child books from within bookstore with the attribute “lang” with a value equal to “en”

48
Q

Basic XQuery FLWOR query syntax

A

for $var in doc([xml file])/(some XPath like path expression)
let $var2 := (some extension to the path expression some other values you might want to use)
where $var/(some predicate not in brackets)
order by $var/(element or attribute)
return $var/(element or attribute)

references to the for variable are done by $var/

49
Q

Whats happening in a FLWOR Query

A

for $var in doc([xml file])/(some XPath like path expression)
let $var2 := (some extension to the path expression some other values you might want to use)
where $var/(some predicate not in brackets)
order by $var/(element or attribute)
return $var/(element or attribute)

The $var/ variable in the “for” expression is bound to each element in the sequence obtained by the path expression. That element then go through the query and will be returned if satisfies the query

The $var2/ variable in the “let” expression is bound to the ENTIRE SEQUENCE elements (not each element at a time)

50
Q

«12345» hello

A