Chapter 7 Querying and Managing XML Data Flashcards Preview

70-461 > Chapter 7 Querying and Managing XML Data > Flashcards

Flashcards in Chapter 7 Querying and Managing XML Data Deck (81)
Loading flashcards...
1

What is XQuery?

It's short for XML Query Language. It's the standard language used to query and manipulate XML data.

2

What are elements?

Elements are part of an XML document. They are made up of a begin tag and an end tag. Elements can be nested.

3

What are tags?

Tags are used to name parts of an XML document, e.g. . Tags cannot be interleaved.

4

What is an XML document?

TODO

5

What is a well-formed XML document?

An XML document is said to be well formed if every begin tag has a corresponding end tag and if tags are nested properly.

6

Are XML documents "ordered"?

Yes, but not by any specific element value; it means the position of elements matters.

7

Is XML case-sensitive?

Yes. XML is case-sensitive unicode text.

8

What is markup?

Characters that have special meaning such as ' which introduces a tag.

9

What do you do if you want to include markup in the values of your XML?

They must be escaped by using an ampersand (&), a special code, followed by a semicolon (;). For example:
& => &
" => "
< => <
> => >
' => '

10

What is XML CDATA?

CDATA is short for character data. This will prevent special characters in the string from being parsed as XML makup. It's written as The ... can be replaced with any character string.

11

What is the prolog of an XML document?

The prolog occurs at the beginning of the document and denotes the XML version and encoding of the document, such as

12

What is an XML fragment and how is it different from an XML document?

An XML document has a single root node. A fragment does not have a root node.

13

What are attributes?

Attributes are name value pairs that are listed on elements. They have their own names and their values are enclosed in quotation marks.

14

What is an attribute centric presentation?

Where each "property" is written as an attribute on the elements.

15

What is an element centric presentation?

Where each "property" is written as a nested element of the original element.

16

Do element names need to be unique?

No, element names do not have to be unique because they can be referred to by their position.

17

What are namespaces?

Namespaces can be used to distinguish elements that share the same name. You declare namespaces that are used in the root element of an XML document. You can also add an alias for each namespace. The namespace alias is used to prefix element names, e.g.

18

What is a schema?

Describes the metadata of XML documents. Currently, the most widely used metadata description is with XML Schema Description (XSD) documents. XSD documents are XML documents that describe the metadata of other XML documents. It includes element names, data types, number of occurrences of an element, constraints, and more.

19

What is a typed XML document?

A document with a predefined schema. A document that complies with or has been validated against a schema.

20

How do you produce XML from relational data?

Use SELECT ... FROM ... FOR XML construct.

21

What does the FOR XML RAW option do?

In RAW mode, every row from returned rowsets converts to a single element named row and columns translate to the attributes of this element, e.g. This behavior can be enhanced to include a root element, namespaces, and making the XML element-centric, e.g. FOR XML RAW, ROOT('ProductModel'), ELEMENTS.

22

What does the FOR XML AUTO option do?

AUTO mode generates nested elements in the resulting XML using heuristics based on the way the SELECT statement is specified, e.g. JOINS, etc. You have minimal control over the shape of the XML generated.

23

In AUTO and RAW modes, what does the ELEMENTS KEYWORD do for you?

Produces element-centric XML, e.g. FOR XML AUTO, ELEMENTS

24

What does the WITH NAMESPACES clause do?

The WITH NAMESPACES clause precedes the SELECT part of the query and defines the namespaces and aliases in the returned XML, e.g. WITH XMLNAMESPACES('TK461-CustomersOrders' AS co)... SELECT

25

How are the table and column aliases in the query used to produce element names?

You can alias column and table names such as SELECT [co:Customer].custid as [co:custid]
FROM Sales.Customers AS [co:Customer]
using a colon to separate the namespace from the element and this will in turn produce the element names.

26

Why is ORDER BY important when using T-SQL SELECT to format and return XML?

Without the ORDER BY clause, the order of rows returned is unpredictable and you can get a weird XML document with an element repeated multiple times with just part of the nested elements every time.

27

Where does the FOR XML clause go in relation to the ORDER BY clause?

The FOR XML clause comes after the ORDER BY clause in a query.

28

Why is the order of columns important when using T-SQL SELECT to format and return XML?

SQL Server uses column order to determine the nesting of elements. The order of the columns should follow one-to-many relationships. A customer can have many orders; therefore, you should have the customer columns before the order columns in your query.

29

What does the XMLSCHEMA option do?

FOR XML in both RAW and AUTO modes can also return the XSD schema of the document you are creating. This schema is included inside the XML that is returned before the actual data - i.e. it is called inline schema. The XMLSCHEMA directive accepts a parameter where you define a target namespace, e.g. FOR XML AUTO, ELEMENTS, XMLSCHEMA('TK461-CustomersOrders');

30

How can you use the XMLSCHEMA option to only export the schema and not include any data?

Simply include a WHERE condition in your query with a predicate that no row can satisfy, e.g. WHERE 1 = 2 FOR XML AUTO, ELEMENTS, XMLSCHEMA('TK461-CustomersOrders');