3.4. Map order
This section discusses the object-relational mapping how to process the order.
3.4.1. Same order, level order, and document order
Sibling means "brothers and sisters." That is, the same level or PCDATA is an element or PCDATA with the same parent element. In other words, they appear in the same content model. For example, if the document is represented as a tree in the previous chapter, this is easy to display those elements: these elements are at the second level of this level, and there are A as their parent elements.
A
_______________________________________________
| | | | | | | | | | |
THIS TEXT C Makes B No Sense C Except as b An Example
| | | | | |
CC BBBB CCCC BB
Note that the element of the third level at the level is not as level because they do not share the same parent element. This also points out the order of the same level, which is the order of their parent element, and the order of hierarchy, which is the level of the child in the tree that represents the document, the difference between the two. Different documents, it is the order of elements and text appears in an XML document. E.g:
The order of the same level (only one of the places of the same level is not displayed):
A
_______________________________________________
| | | | | | | | | | |
THIS TEXT C Makes B No Sense C Except as b An Example
1 2 3 4 5 6 7 8 9
| | | | | |
CC BBBB CCCC BB
Hierarchical order:
1 a
_______________________________________________
| | | | | | | | | | |
2 THIS TEXT C Makes B No Sense C Except as b An EXAMPLE
| | | | | |
3 CC BBBB CCCC BB
Document order:
A
1
_______________________________________________
| | | | | | | | | | |
THIS TEXT C Makes B No Sense C Except as b An Example
2 3 5 6 8 9 11 12 14
| | | | | |
CC BBBB CCCC BB
4 7 10 13
According to XML, the same order is important. In fact, this depends on the application. For example, in a data-centric application, use an XML document to pass an object or table, the same order is usually irrelevant because the object-oriented language does not have the concept of the order between class properties. Similarly, the relational database is not the concept of the order between columns. Therefore, the same order is not important in the following documents:
Part>
Part>
They are all mapped into the following objects and rows in the table:
Object table
========================= ================================================================================================================================================================================================== ==========
Table Parts
Object Part {-------------------------------
Number = 123 ==> Number DESC PRICE
DESC = "Turkey Wrench" -----------------------
Price = 10.95 123 Turkey Wrench 10.95
(One of the main exceptions to this is when you must match a specific DTD in data-centric documents. This occurs when an application must verify the document, such as when they come from unknown or not trusted sources. Although in this case, the "all group" of XML Schemas can be homped by allowing a group of child elements to be helped in any order, but they do not support repeating sub-elements.)
On the other hand, in a document-centric application, the usual document is designed for people's consumption, and the order of the same level is very important. For example, I am likely to like the first comment rather than the second:
ronald bourret is a
Excellent writer b>.
Only fool b>
I don't read his work. p>
Review>
ronald bourret is a
Fool B>. only
Excellent writer b>
I don't read his work. p>
Review>
Object-Relational Mapping can keep the same level, which will be seen below, although it is actually rarely supports it. By mapping the column in the simple element type to the column in the table, and the reference to the complex element type is mapped to the primary key, the foreign key contact, its instinct is in order. The order of documents is retained in the order of hierarchical order and the same level. 3.4.2. Map of the same order
Because the object-oriented language has no concepts between the class properties, the relationship database does not have the order of the order between the columns, and the same order value must be stored independently with the data value. One way to do this is to intervene independent class properties and columns in which order values are stored. Another way to do this is stored in the mapping of itself.
3.4.2.1. Order properties and columns
Use the order class attributes and subsequences to store order values. They are opposite to data class properties and data columns. Each of the referenced elements or PCDATAs that are important for the order of the items require a class attribute or column. For example, consider an example of the above mixed content. The same order in the DTD is mapped to the order class attribute:
DTD class
================================================== =====
Class a {
String [] PCDATA;
int [] pcdataorder;
string [] b;
==> int [] border;
string [] C;
Int [] CORDER;
}
And then map to the sequence:
Class table
============================================================================================================================================= ==============
Table PCData
Class a {----- column a_fk
String [] pcdata; / column pcdata
int [] pcdataorder; / column pcdataorder
String [] B; Table A / Table B
Int [] border; ==> column a_pk -------- Column a_fkstring [] C; / Column B
int [] CORDER; / Column Border
} / Table C
/ ---- COLUMN A_FK
Column C
Column Corder
Note that the order class attribute stored in the standard is stripped in parallel.
The following example shows the use of the order attribute to retain the same order in the "Makes-NO-Sense" example. It is important thing to pay attention to here that all order class properties share the same order space. A sequence value that appears in one order class attribute does not appear in another order class property.
Class table
================================= ================================================================================================================== ====================
Table PCData
A_fk pcdata pcdataorder
---- ---------------------
1 THIS TEXT 1
Object a {1 Makes 3
Pcdata = {"this text", 1 no Sense 5
"Makes", 1 Except as 7
"No Sense", Table A 1 An Example. 9
"eXCEPT AS", A_PK
"an esample."} ==> ---- TABLE B
PcdataRDER = {1, 3, 5, 7, 9} 1 a_fk b border
B = {"bbbb", "bb"} ---- ---- ------
Border = {4, 8} 1 BBBB 4
C = {"cc", "cccc"} 1 BB 8
CORDER = {2, 6}
} Table CA_FK C CORDER
---- ---- ----------
1 CC 2
1 CCCC 6
Although the order class attribute is most commonly used to maintain the order in the mixed content, they can also be used with the element content. For example, consider the following element type definition. Because B can in A, it can appear once, it is stored in a stand-alone attribute table. There is no sequence class attribute, which will not be able to determine how the B child element is seized. (Note that this order cannot be used, because the relational database does not guarantee a row in any particular order.)
3.4.2.2. Store in the mapping
In many cases, the same order is only important when verifying; in addition to verifying a document, it is not concerned about the same order. Especially in data-centric documents. In this case, it is sufficient to store the order information in the mapping itself.
For example, the following content model is given, and the order of the sub-elements that can store A is B and then the information of d:
In particular, it is limited to store order information in the mapping. For example, consider the following content model:
Texture Matching this content model The document requires that software first decides how much data can be obtained to construct B elements. If there is only enough data to construct a B element, it cannot be the first B element because the second B element is necessary.
Let most software so troublesome are unlikely. Turns, only those content models of all the same elements of the same element type together provide reasonable restrictions. It is sufficient for many data-centric content models and can be implemented by storing each element in the mapping.
For example, the order of the peer elements in the following elements can be mapped. Note that both of Author and Editor can be given the same order value or different values in the third content model; if they are given different values, all elements of one type will appear in other types of any elements. Front.
When the order information is only stored in the mapping, as long as the content model contains more than one of the same type of element, the non-destructive flow of the document is not possible. For example, consider the following content model:
Although the mapping can tell the software that all B elements must appear in front of the C element, it cannot specify the order of the B element. So, if the data is transmitted from the document containing this content model and then transfer it back, the B element cannot be guaranteed in the order in the original document. Fortunately, this is usually not a problem with data-centric documents.
3.5. Mapping properties
As seen in the previous, map the attribute map to the scalar property. This section will discuss details of this mapping, there are other points.
3.5.1. Map single value and multi-value properties
There are two different properties: single value (CDATA, ID, IDREF, NMTOKEN, Entity, Notation, and Enumeration) and multiple values (idRefs, NMTOKENS, and Entities). It is expected that it is possible to map them into single-value class properties (the terminal is column) and multi-value class properties (then attribute table). E.g:
DTD class ======================================== ======= ====
Class A {Table A
COLUMN B; Column B
D cdata #Required> ==> string c; ==> Column C
string d; Column D
}
with:
DTD class table
======================================= ======================================================================================================================================= ==
Class A {Table A
D idrefs #implied> ==> string c; ==> Column B
string [] d; color
} TABLE D
Column a_fk
Column D
It is not important in the order of XML information set properties. For example, the following two XMLs are considered to be equal. Therefore, there is no need to maintain the order of the properties to maintain the order of properties, although it is entirely possible.
C = "CCC" D = "ddd" />
B = "bbb" D = "ddd" /> On the other hand, the order in which the value appears in the multi-value attribute is considered to be important. This is the case of the same level element and PCDATA, and the order class attribute can be used to maintain information about the order of the value in the multi-value attribute. However, there is an important difference between the order class attribute used for the same level and PCData, and the order class attribute for multi-value attributes: each order class attribute for multi-value attribute has its own order. space. This can be seen in the examples below: XML object ======================================================================================================================================= Object a { ID / IDREF (s) attribute mapping is the primary key, foreign key contact. For example, the above document can be stored in the database as the following list and columns: Table a Column a_pk ... / / / / TABLE B TABLE C Column a_fk column a_fk Column Ref_d Column Ref_D ... / / / / Table D Column a_fk COLUMN ID ... When you store ID / IDREF (s) attributes in the database, the data transfer software requires a careful thing that the ID only guarantees that it is unique in a given XML document. Therefore, if data from more than one document is stored in the same table, the ID is unique. The solution to this problem is "Modified" ID in some way. You can map the property to two columns, one column contains a value for each document, and the other column contains ID, or modified the ID itself, such as a prefix with a unique value. There are similar problems when data is transmitted from the database to the XML document. If the data retrieved origines from more than one document, the data transfer software needs to make sure the ID value is unique. This may involve changing one or more values, together with all the values of all the idRef (s) properties that reference them. Currently, most products do not support ID / IDREF as an attribute that is different from other properties. 3.5.3. Mapping Note Attribute Use a notation in an XML document to remind the application how to handle an element or an unsatisfactory entity. For example, the following "XHTML" notes can tell to apply this element containing XHTML and should use a browser to display:
a us Big b> Turkey Wrench. p>
body>
html>
Desc>
The notes attributes and their values are not significant for object-relationship mapping; treat them as simple to another attribute.
The only exception to this occurs when the data type of the text indicating the text included. For example, a note "Base64" can tell an element encoded to base64 (mapping binary data to a subset of US-ASCII). MIME encoding). In most cases, this information is only meaningful for the software generated mapped. It can use this information to map element types to binary value class properties and then go to blob (binary large object). In these cases, map itself does not use this information. The mapping from the element to the blob independently of the facts containing data type information.
The only exception to this is when the data transfer software is complex to the notation value to switch the mapping at runtime. In this case, each possible note is mapped into a data type, then use it to convert the data.
3.5.4. Mapping Entity / Entities attribute
Using the Entity and Entities properties to associate unsatisfactory, external data (such as one binary) with the XML document. Maps them are the same as any other attribute. Different, when transmitting data, use the entity replacement attribute value (when transmitting data from XML to the database), or can create a new entity and store it as attributes Value (when data is transmitted from the database to XML). Because the unlocked entity value can be generated, the mapping specifies that the value is stored in the database or the entity URI is a good idea.
These notes may be used when the data type (mapping time or run time) is determined when the unsatisfactory entity is always related.
3.6. Alternative mapping
In the previous chapter, we have described how to map DTDs to the database. In fact, these descriptions are incomplete because there are some other way to complete the mapping. In this section, we will discuss two most important alternatives.
3.6.1. Mapping complex element type to scalar type
Although complex element types are typically mapped into classes and then mapped into tables, they may map them into scale types. In other words, the reference to complex types can be mapped to scale class properties. The value of this type of attribute is generally the element content, serialized to XML. This is useful when the value of the elements is meaningful and should not be decomposed into a smaller portion. For example, consider an XML document regarding information about Part. If a child element is described by partial xhtml, further decomposition it may not make sense. As we have already described, this will cause data to be dispersed into many tables; italic word a table, bold word a table, using a table in HyperLink, and so on. Therefore, it is best to store these descriptions in a single column:
DTD class table
====================================================================================================================================================================================================== ======
Class Part {Table Part
==> String Num; ==> Column Num
From xhtml ->}
For example, the following description will be so stored:
A Very Big b> => ---- ----------------
Turkey Wrench. 127 a Very Big b>
Desc> Turkey Wrench.
Part>
Note that the storage data is XML that does result in data transmission software. In particular, the software cannot distinguish between tags and data. For example, how is the application decided that is a or text in the following text?
An Example of The Element is this element b>.
One solution to this is to store the actual elements in the database, and use entity reference to store characters:
An Example of The
Element is this element b>. What is done is that the non-XML application cannot find the database as they want. 3.6.2. Map Scale Class Properties to the Properties Although single-values, scalar value class properties are typically mapped, and they can also be mapped into a property table. This is useful, for example, stores BLOB or unused class properties in a table independent of the main table. For example: class table ========================================= String Desc; Table Descriptions} Column Num Column Desc 3.7. Conclusion Object - Relationship Mapping Processes all XML documents, valid mapped to objects and allows non-XML applications to use data in the database. Therefore, for data-centric documents is a good idea and (not strange) in certain middleware, most enabled XML databases, and most enabled XML object servers as the underlying model. It should be noted that all of these products implements a slight version of the object-relational map, and there is no possible thing that implements all possible things. In a more common portion of the map, the complex element is mapped into classes and mapped into class properties, the same use primary key, foreign key pair. However, some only on the PCData element map column, others only map columns, there are some other allowed two. Similarly, most of these products do not support the same order or mixed content, and many of them do not allow users to change the name during mapping. Object-Relational Mappings are not a good choice for normal documents. First, it is inefficient when mixing the content. Second, like a table-based mapping, it does not retain physical structures, annotations, and processing instructions. 4. Generate mode We now consider how to generate relational database patterns from DTD based on object-relational mappings and vice versa. Because there is a lot of possible paths through the object-relationship map, the algorithm here is the most often used branch in each selected. For example, a single reference to the only PCDATA element can be mapped into a column or a separate attribute table. Because the most common choice is to map them, the following algorithms generate a column from such a reference. For object-oriented databases, the generation process is similar. 4.1. From the DTD generation relational database mode By reading the DTD and handles each element type to generate a relational mode: complex element type generates class tables with primary key columns. In addition to ignoring the simple element type outside of the processing content model. To process a type model:
A single reference to a simple element type; if this reference is an optional (? Operator), this column is null. Repeated reference to simple element types Generate an attribute table with foreign keys. Reference to complex element types is generated outside of the remote (Remote) class table. The PCDATA in the mixed content generates an attribute table with a foreign key. A column that is randomly generated for all referenced element types and PCDATA. To process properties:
Single value attribute generation column; if the property is optional, this column is empty. Multi-value properties Generate an attribute table with foreign keys. If an attribute has a default, it is used as a list of columns. The following example shows how this process works.
Consider the following DTD: DTD table ============================================ ===== ================= In the first step, we generate tables and these tables for complex element types: DTD table ======== ==================================================================================================================================================== ======== ==> Table Order Column ORDERPK ==> Table Item Column Itempk <
Element Quantity (#pcdata)> ==> Table Part Column Partpk In the second step, we are To the simple element type reference generation column: DTD table ======================================= =========================== ==> Table Order Column OrderPK Column OrderNum Column Date Column CustNum ==> Table Item < ! Element itemnum (#pcdata)> Column itempk Column Itemnum Column Quantity ==> Table Part Column Partpk
COLUMN PARTNUM Column Price In the final step, we build foreign key for the complex element type: DTD table ============================ ===================== ==================================================================================================================================== *)> ==> Table Order Column ORDERPK Column ORDERNUM Column Date Column Custnum ==> Table Item Column Itempk Column Itemnum Column Quantity Column ORDERFK ==> Table Part Column Partpk
The Column Partnum Column Price Column Partfk generated mode will not be the same as manually written mode. In addition to naming problems (for example, one person may call the table orders, items, and parts), generating an algorithm cannot be determined that direct contacts directly in Items and Parts are multi-one. This algorithm does not recognize ORDERNUM and PARTNUM can be used as the primary key, and it cannot determine the data type and column length, and XML Schemas solves the latter problem. Although there is no name conflict or illegal name generation, both are possible. 4.2. Generate DTD from the database mode Generate DTD from a single "root" table or a set of root tables and handles each root table: each root table generates an element type with a single sequence form. Each of the data (non-keys) columns are generated into one element type with only PCDATA content and one reference in the sequence; the column with null value generates an optional reference. The primary key and foreign key are generated as follows:
The remote mesh is handled in the same way. Adding a reference to the element type of the far end to the sequence. If the key is the primary key, the reference is an optional and repetitive (* operator). This is because you can't guarantee that there is a line in the outer key table, and you can't guarantee that there is only one way. If the key is the primary key, the type of only PCDATA is generated at each column in this button. If they generate, add them to the sequence to these element types. This is only useful when the primary key contains data. If the key is foreign key and has a null value, the reference is an optional (? Operator). During this processing, the key (if any) to the table (if any) is not processed. This avoids the algorithm to repeat the type of elements established in the parent table. The following example shows how this process works.
Consider the following database schema: Table Orders Column OrderNum Column Date Column CustNum Table Items Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price In a first step, we generate a root element type table (Orders): Table DTD == ================ ==================================================================================================================================== ================= Table Orders ==> Column OrderNum Column Date Column CustNum Table Items Column OrderNum Column itemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price then generates only PCDATA elements for data columns (Date and Custnum) and adds a reference to these elements in the content model of the Orders element: Table DTD ================ == ================================================================================================================================================================================================== === Table Orders ==> Column ORDERNUM COLUMN DATE Column Custnum
Table Items Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price Now the primary key (OrderNum) to generate a PCDATA-only element content model to add a reference to it: Table DTD ========= ========= =========================================================================================================================================================================== ========== Table ORDERS ==> Column ORDERNUM Column Date Column> Column> Column> Column> Column> Column> Column CustNum table Items Column OrderNum Column itemNum Column Quantity Column PartNum table Parts Column PartNum Column Price then be exported to the primary key wherein the table (the Items) add an element type, in which the same content model A reference to it: Table DTD ========================================== ============================ Table Orders Column ORDERNUM
Column Date Column CustNum Table Items ==> Column OrderNum Column ItemNum Column Quantity Column PartNum Table Parts Column PartNum Column Price We Treated data and primary key columns in the remote (items) table: Table DTD =============================== =============================================== Table Orders Column OrderNum Column Date Column CustNum Table Items ==> Column OrderNum Column Itemnum Column Quantity Column Partn UM Table Parts Column Partnum Column Price Added an element to the table (Parts) corresponding to the foreign key: Table DTD ============================ ====================
======================= Table Orders Column ORDERNUM Column Date Column CustNum Table Items Column OrderNum Column itemNum Column Quantity Column Partnum Table Parts ==> Column Partn PARTNUMN PRICE Finally, we handle foreign key table (Parts): Table DTD ======== ========== ============================================================================================================================================================================== =========== Table Orders Column ORDERNUM Column Date Column Custnum Table Items Column OrderNum Column ItemNum