XML Attributes and Elements Flashcards

1
Q

What does XML stand for

A

eXtensible Markup Language (similar to HTML)

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

XML is designed to

A

support documents that contain structured information. It is commonly used for data interchange and data storage

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

What format was used before XML

A

CSV (comma separated values)

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

Problems associated with no standards for data interchange include:

A

Difficult to read, Hard to validate, Error prone

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

XML Code Example:

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

How is XML similar to HTML

A

they both came from SGML - standard generalized markup language

Markup language: the markup is separate from the content

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

HTML example

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

Well-Formed XML must have

A

a corresponding end tag for all of its start tags. Nesting of elements within each other in an XML document must be proper. For example,

<Order><id>12</id></Order>

is a correct way of nesting and

<Order><id>12</Order><id>id> is not

In each element two attributes must not have the same value. Example:
<Quantity>12</Quantity> is correct
<Quantity unit="in" unit'="lg">/Quantity> is incorrect

-Markup characters must be properly specified.
-An XML document can contain only one root element. So the root element of an XML document is an element that is preset only once in an XML document, and it does not appear as a child element within any other element.
-There are additional rules for well-formed XML documents as well https://www.w3resource.com/xml/well-formed.php for more info
</id></id></Order>

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

Parts of an XML Document - XML Declaration

A

Optional but recommended
-Version number: Required if declaration is present, often it is 1.0
-Encoding: Optional, XML parsers usually detect UTF-8 and UTF-16

<?xml version=”1.0” encoding = “utf-8”?>

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

Parts of an XML Document - XML Elements:

A

Hierarchical with start and end tags

<Item>Food Processor</Item>

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

Parts of an XML Document - XML Attributes:

A

Attributes appear in the start tag and must have a unique name. Attribute value must be enclosed in quotes

<Quantity>.
</Quantity>

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

Parts of an XML Document - Comments:

A

Comments cannot appear above the XML declaration and may span multiple lines. Provides extra information about the document.

<! - - This is a comment - - >

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

Parts of an XML Document - CDATA:

A

This is raw character data and allows the use of non-ascii characters.

<![CDATA[
Can use different characters for a description&raquo_space;&laquo_space;& and reserved characters
] ]>

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

Attributes Versus Elements

A

There are no rules when to use attributes versus elements, but many developers follow guidelines; for example, using elements for data and attributes for information that is peripheral or incidental to the data.
-Use elements instead of attributes
-Metadata should be stored as attributes
-Use an attribute if it influences and element value
-Do not use an attribute that influences another attribute
-Instead of using multiple attributes consider using child elements

Child Elements

<person>
<firstname>Ben</firstname>
<lastname>Solo</lastname>
<age>25</age>
</person>

One Attribute

<person>
<firstname>Ben</firstname>
<lastname>Solo</lastname>
</person>

All attributes

<person></person>

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

XML Element Relationships (with example)

A

Children are elements directly beneath a parent element. <book><title><author><year><price> are all children of <bookstore>.</bookstore></price></year></author></title></book>

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

XML Ancestors and Descendants

A

A descendant element is one that is contained within another element. For example,

<Items> is a child of <Order>
<Items> elements are children of <Items>

<Item> is a descendent of <Order>

<Order> is an ancestor of <Item>

EML Example:

![!BS! ](https://s3.amazonaws.com/brainscape-prod/system/cm/491/846/056/a_image_ios.?1709846180 "eyJvcmlnaW5hbFVybCI6Imh0dHBzOi8vczMuYW1hem9uYXdzLmNvbS9icmFpbnNjYXBlLXByb2Qvc3lzdGVtL2NtLzQ5MS84NDYvMDU2L2FfaW1hZ2Vfb3JpZ2luYWwuPzBkNjY5NmE4OTJlYWUxMjYzODVhMTk0OTEzOWYzNjViIn0=")
</Item></Order></Order></Item></Items></Items></Order></Items>

17
Q

XML Namespaces

A

Namespaces are used to provide different elements and attributes within an XML document to prevent name conflicts.

Namespace is a URL http://mycompany.com/order
in this example but does not have to be a URL

Namespaces are reserved attributes:
“xmins” or “xmins:”

You can provide a default namespace to a specific element such as the Order element

All elements and attributes are in the http://mycompany.com/order namespace because it applies to Order and all of its descendants

18
Q

XML Prefixes

A

All elements and attributes that are prefixed with”it:” are part of the xmins:it=http://mycompany/item namespace

The order ID element and the Item ID element are different namespaces. So the elements are uniquely identified.

19
Q
A