Computers and computing systems have affected nearly every aspect of modern living. Computers are generally involved in work, recreation, healthcare, transportation, entertainment, household management, etc.
An LOB (line-of-business) application is a computer application used to run some portion or aspect of an enterprise. For example, an LOB application may be an inventory management application, a customer database application, an accounting application, an e-commerce application, etc.
Typically, an LOB application communicates using a proprietary communication language and protocol. In contrast, clients wishing to communicate with LOB applications could communicate with just XML (eXtensible Markup Language) messages. To bridge LOB applications and clients, adapters may be implemented to translate the XML messages to the proprietary LOB application messages.
The subject matter claimed herein is not limited to embodiments that solve any disadvantages or that operate only in environments such as those described above. Rather, this background is only provided to illustrate one exemplary technology area where some embodiments described herein may be practiced.
One embodiment described herein includes a method that may be practiced in a computing environment. The method includes acts for storing mark-up language representations of data as a complex relational database structure. The method includes receiving an XSD (XML Schema Definition) document. The XSD document defines at least one type that should be mapped to a complex relational database type. The XSD document is mapped to a relational database structure. An XML document is received. The XML document is interpreted according to the XSD document. One or more elements of the XML document are mapped to complex relational database elements based on mapping of the XSD document to the relational database structure.
Yet another embodiment is directed to a method of storing mark-up language representations of data in a complex relational database structure. The method may be practiced in a computing environment. The method includes receiving an XML document. The method further includes determining that the XML document includes elements that should be mapped to a complex relational database structure. The elements are mapped to a complex relational database structure.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used as an aid in determining the scope of the claimed subject matter.
Additional features and advantages will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the teachings herein. Features and advantages of the invention may be realized and obtained by means of the instruments and combinations particularly pointed out in the appended claims. Features of the present invention will become more fully apparent from the following description and appended claims, or may be learned by the practice of the invention as set forth hereinafter.
In order to describe the manner in which the above-recited and other advantages and features can be obtained, a more particular description of the subject matter briefly described above will be rendered by reference to specific embodiments which are illustrated in the appended drawings. Understanding that these drawings depict only typical embodiments and are not therefore to be considered to be limiting in scope, embodiments will be described and explained with additional specificity and detail through the use of the accompanying drawings in which:
Some embodiments described herein are directed to facilitating communication between relational database systems and systems that communicate primarily using hierarchical based mark-up language messages. For example, some embodiments may be directed to interfacing adapters which communicate using XML messages with clients that include relational databases or relational database applications. Additionally, some embodiments include functionality for allowing data expressed as complex XML elements or attributes to be stored as complex relational database elements. Complex relational database elements may include nested tables, columns or rows. Further, other simple XML elements may also be stored as complex relational database elements when appropriate, as explained in more detail below.
Referring now to
This facilitates an ability for clients which communicate using XML based messages to communicate with LOB applications 102 through adapters such as the adapter 106. However, as previously described, some clients such as client 104 include relational databases 112 and are configured to communicate using a relational database language including relational database messages such as relational database message 114 illustrated in
An example of this functionality is illustrated now with reference to
<xs:element name=“firstname” type=“xs:string”/>
This code may map to a table containing a single column named “firstname” in a relational database. Other examples, that will be discussed in more detail may be more complex and may include functionality for mapping XML types to complex database elements.
<firstname>Priyaa</firstname>
Illustrating now the embodiment described previously, corresponding XML code is as follow:
<firstname>Priyaa</firstname>
This XML code may be mapped such that the following table appears in the relational database:
The method 300 may further be performed such that mapping elements of the XML document to relational database elements includes mapping names of elements and attributes to tables and columns.
The method 300 may further be performed such that mapping elements of the XML document to relational database elements includes mapping XSD types to CLR (Common Language Runtime) types.
As will be illustrated in a number of the examples below, the method 300 may further be performed such that mapping elements of the XML document to relational database elements includes mapping XML elements that include complex elements to complex relational database columns.
The method 300 may further be performed such that mapping elements of the XML document to relational database elements includes mapping XML elements that do not include complex elements to primitive relational database columns.
The method 300 may further be performed such that mapping elements of the XML document to relational database elements includes determining that an attribute includes a constraint indicating that the attribute is restricted. Based on determining that an attribute includes a constraint indicating that the attribute is restricted, the method 300 further includes excluding the attribute from mapping elements of the XML document to relational database elements.
The method 300 may further be performed such that mapping elements of the XML document to relational database elements includes mapping a default value of an element or attribute specified by the XSD document to a relational database element. In one embodiment, the method 300 may further include validating a user input value by comparing the user input value to the default value. An exception may be thrown if the user input value does not match the default value.
The method 300 may further be performed such that mapping elements of the XML document to relational database elements includes mapping XML sequences that occur more than once to complex relational database columns.
The following now illustrates mapping of a number of different XML types and attributes to relational database elements.
The following examples illustrate example mappings for simple XML types to appropriate relational database mappings. For example, the following illustrates an example where an element occurs a maximum of one time. The following illustrates example XSD code for this instance:
<xs:element name=“firstname” type=“xs:string”/>
An example of corresponding instantiated XML code is as follows:
<firstname>Priyaa</firstname>
The resulting relational database entry is a primitive type column as illustrated below:
In another example, an element may occur a maximum of more than one time. The following illustrates example XSD code for this case:
An example of corresponding instantiated XML code is as follows:
While this example is for a simple XML type, because of the multiple element instances, the resulting relational database entry is a complex type column as illustrated below:
The following illustrate mappings to relational databases from attributes of XML documents. Attributes can generally be mapped to simple or primitive relational database elements.
The following illustrates example XSD code for attributes:
An example of corresponding instantiated XML code is as follows:
<Age country=“neverland”>30</Age>
This XML code may be mapped to a primitive type column as illustrated in the following example:
The following illustrate complex XML types. One complex XML type is a type which includes empty elements. The following illustrates example XSD code for such a type:
<xs:element name=“firstname” type=“xs:string”/>
An example of corresponding instantiated XML code is as follows:
<firstname/>
This XML code may be mapped to a primitive type column as illustrated in the following example:
Another complex XML type may include empty elements with attribute(s). The following illustrates example XSD code for such a type:
An example of corresponding instantiated XML code is as follows:
<Age country=“neverland”/>
This XML code may be mapped to a primitive type column as illustrated in the following example:
Another complex XML type includes empty elements that contain only text or other simple content. The following illustrates example XSD code for such an example:
An example of corresponding instantiated XML code is as follows:
<Age>30</Age>
The resulting relational database table includes a primitive type column. An example is illustrated below:
Another complex XML type includes elements with only child elements with which occur a maximum of one time. The following illustrates example XSD code for an example embodiment:
An example of corresponding instantiated XML code is as follows:
The resultant relational database table is a table with primitive type columns as illustrated below:
Another complex XML type includes elements with only child elements that occur a maximum number of times more than one. The following illustrates example XSD code for this embodiment:
An example of corresponding instantiated XML code is as follows:
The preceding XML code maps to a complex table as illustrated below:
Another example of a complex XML type includes an XML element with a complex element and occurs a maximum of one time. The following illustrates example XSD code for this example:
An example of corresponding instantiated XML code is as follows:
This XML code maps to a complex table with a complex column, such as is illustrated below:
Another example of a complex XML type includes an XML element with a complex element that has a maximum occurrence of more than one. The following illustrates example XSD code for this example:
An example of corresponding instantiated XML code is as follows:
This XML code maps to a complex table with complex columns with multiple rows as shown in the following example:
Another example of a complex XML type includes an XML element with complex and simple elements mixed. The following illustrates example XSD code for this example:
An example of corresponding instantiated XML code is as follows:
The following illustrates mapping of the above XML to a complex table with complex type and simple type columns:
Another example of a complex XML type includes an element with complex and simple element and occurs a maximum number of times greater than one. The following illustrates example XSD code for this example:
An example of corresponding instantiated XML code is as follows:
Mapping this XML code to a relational database results in a complex table with complex type columns, such as the example table illustrated below:
Embodiments may be configured such that the XML data reader 116 understands occurrence constraints for the purpose of creating the correct relational shape so that the associated XML data can be correctly shredded into it. The XML data reader 116 may use occurrence information to determine if element is single valued or multi-valued. This means all MaxOccurs>1 or MinOccurs>1 are treated as many valued and are promoted to MaxOccurs=unbounded and treated as a many valued elements.
In some embodiments, elements that have MinOccurs=0 and MaxOccurs=0 will be ignored. This is done, in some embodiments, because a sever object management data model may strip out such elements during compilation such that these elements are not available to the XML data reader 116.
In some embodiments, if attributes are constrained by an identifier that identifies them as prohibited use, they are excluded from the mapping.
An element or attribute with a simple type list may be mapped to CLR type List<T> where T is the CLR type associated with the item type of the list. For dataset mapping, list types may be mapped to columns of type string.
An element or attribute with a union simple type may be mapped to the untyped CLR type object. Simple types defined using union can have contents from any of the simple types that are part of the union. It may not possible to map union simple type definitions to a single strongly typed CLR types. Thus, in one embodiment a union simple type definition is mapped to a system object type. For dataset mapping, union types are mapped to string as object types may not be mapped to attributes in dataset.
The Xml data reader 116 will support default or fixed facets associated with elements or attributes in the input XSD schema. Row instances will receive the default/fixed value for the respective columns if either the associated element/attribute is missing.
In cases where a fixed value is provided in the XSD schema for a given element/ attribute and the user provides an explicit value for the same element/ attribute values via the source document, the Xml data reader 116 will validate that the instance value matches the fixed value via a lexical comparison. If the values do not match, in one embodiment, an exception will be thrown.
A given XSD schema instance can be thought of as closed when it does not make use of any element or any attribute. If any constructs are used then the XSD schema can be thought of as being open. An XML instance associated with such schema can replace the any element and any attribute with other appropriate attributes and elements. In one embodiment, the Xml data reader 116 will treat content associated with any element and any attribute as extra content and will ignore it.
The following table illustrates illustrative mapping that may be performed:
Embodiments herein may comprise a special purpose or general-purpose computer including various computer hardware, as discussed in greater detail below.
Embodiments may also include computer-readable media for carrying or having computer-executable instructions or data structures stored thereon. Such computer-readable media can be any available media that can be accessed by a general purpose or special purpose computer. By way of example, and not limitation, such computer-readable media can comprise RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to carry or store desired program code means in the form of computer-executable instructions or data structures and which can be accessed by a general purpose or special purpose computer. When information is transferred or provided over a network or another communications connection (either hardwired, wireless, or a combination of hardwired or wireless) to a computer, the computer properly views the connection as a computer-readable medium. Thus, any such connection is properly termed a computer-readable medium. Combinations of the above should also be included within the scope of computer-readable media.
Computer-executable instructions comprise, for example, instructions and data which cause a general purpose computer, special purpose computer, or special purpose processing device to perform a certain function or group of functions. Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.
The present invention may be embodied in other specific forms without departing from its spirit or essential characteristics. The described embodiments are to be considered in all respects only as illustrative and not restrictive. The scope of the invention is, therefore, indicated by the appended claims rather than by the foregoing description. All changes which come within the meaning and range of equivalency of the claims are to be embraced within their scope.