A UNIVERSAL OUTPUT CONSTRUCTOR FOR XML QUERIES

Abstract: A mapping language, insertable into a DTD, allows automatic mapping from data sources into XML. A mapping results from the establishment of a correspondence between entities in a data source on the one hand and lists and scalars on the other hand. The language maps the lists and scalars to XML elements and attributes. The mapping language includes two constructs: the binding specification and the value specification. The value specification associates with a value or choice declaration. The binding specification includes at least one variable/expression pair. The constructs are insertable into a DTD to create an annotated DTD.

Description: A UNIVERSAL OUTPUT CONSTRUCTOR FOR XML QUERIES Field of the Invention The present invention is related to the field of information retrieval and data integration and, more particularly, to methods and apparatus for processing one or more extensible Markup Language (XML) queries . Background of the Invention The extensible Markup Language (XML) is emerging as one of the most important formats for document and data representation and transmission. For example, business documents can be presented by XML for Internet transmission and World Wide Web access. More and more users and new applications are starting to require their input and output to be in XML format . Details of XML are described in "Extensible Markup Language (XML) 1.0," W3C Recommendation 10-Feb-98. However, the aspects of XML necessary for an understanding of the present invention are provided herein. For XML documents, there is the concept of a Document Type Definition (DTD) . Each DTD describes the structure of a (potentially infinitely large) set of XML documents. An XML document can have an associated DTD or no corresponding DTD at all. When an XML document is associated with a DTD, its structure must conform to the specification of the DTD. An XML document is "well-formed" if it is grammatically correct and the tags are properly nested. An XML document is "valid" if it conforms to a specific DTD. XML query languages, e.g., XML-QL and XQL, enable users to ask questions of XML documents and usually return the answers also in the form of XML documents. XML addressing mechanisms, e.g., XPath, identify elements inside XML documents. For ease of discussion, we will refer to all of them as XML query languages. Current XML query mechanisms generally contain the following logical steps : 1. Query scope identification: usually one or more XML documents or one or more XML elements within some document (s) are identified as being within the query scope . 2. Filtering: select data items to be used as result from the query scope. 3. Output construction: converting and constructing the selected data items into some desirable output format and structure. An XML document can be modeled as a tree, see "Document Object Model (DOM) Level 1 Specification, version 1.0," W3C Recommendation l-Oct-98. The filtering step of XML query languages usually either identifies lists of data or elements (scalar-based filtering) , or lists of subtrees (subtree-based filtering) . The query language may provide a construction mechanism and convert the lists into an XML document in the output construction step. For the case of subtrees, each subtree is rooted at some selected element in the query scope. The construction step of current query mechanisms is highly unstructured and ad hoc. Some query languages, e.g., XML-QL, allow the above-described three steps to be nested or recursively mixed. Most construction steps are XML instance-based instead of DTD-based. That means the outputs of such queries are well-formed, but not necessarily valid (conforming to a DTD) XML documents. In many situations, it is necessary to make the output XML document of an XML query conform to a certain DTD. In e-business applications, trading partners may have mutually agreed upon DTDs to which the exchanged XML documents must conform. If the query outputs are valid, they can be used by trading partners immediately. Such task, although possible through ad hoc manipulation of the query output, is inconvenient and hard to guarantee correctness. Furthermore, the XML query languages or expressions proposed so far do not mix among different query languages or expressions . Suπ-mary of the Invention Accordingly, the invention provides a method of processing one or more extensible Markup Language (XML) queries, the method comprising the steps of: generating a mapping construct which maps a predetermined document type definition (DTD) to one or more data sources to be accessed in response to the one or more XML queries; evaluating the one or more XML queries in accordance with the mapping construct; and generating an XML document resulting from the query evaluation wherein the resulting XML document conforms to the predetermined DTD. Preferably methods and apparatus are provided for query and access of data from various data sources as integrated XML documents, for guaranteeing that the query outputs conform to the DTD of users' choice, and for generating XML documents based on the combination of different XML queries . Preferably the mapping construct includes a binding specification and the one or more XML queries are bound to one or more binding variables . Further preferably the one or more XML queries are evaluated in accordance with the binding specification of the mapping construct and the evaluation result is assigned to the one or more binding variables. The present invention preferably provides methods and apparatus that guarantee that the query output conforms to the DTD of the user's choice. The following are preferably allowed for: (i) selection of a DTD; (ii) integration of one or more XML queries with the DTD; and (iii) in accordance with the provided algorithm, automatic generation of a valid output XML document conforming to the DTD, using the data selected by the XML queries as content of the XML document . It is to be appreciated that the one or more XML queries may be written in one or more XML query languages. Also, the resulting XML document may be a combination of more than one XML query associated with one or more query languages. The resulting XML document may also be a combination of one or more XML queries and one or more non-XML queries. Further, the DTD is preferably specified by a user. In a preferred embodiment, the mapping construct generation step comprises the steps of: (i) determining suitable DTD constructs; (ii) binding the constructs to variables; (iii) associating the variables with a partial XML result obtained from scoping and filtering stages of the XML query; and (iv) distributing the variables to suitable DTD constructs with value functions. Further, the method preferably comprises the step of accepting scalar-based results from the scoping and filtering stages. Also, subtree-based results may be accepted from the scoping and filtering stages. The method further preferably comprises the step of allowing the bindings to be used as parameters in at least one of value generation functions and other binding functions. Further, the method further preferably comprises the step of resolving a nested or recursive filtering query construct with sequential cascade binding constructs. In a preferred embodiment, the query evaluation step comprises the step of combining different parsing and evaluating mechanisms for evaluating XML queries from different XML query languages. Preferably binding variables are permitted to be used in one or more XML queries of different query languages. Further, one or more XML queries of different query languages are preferably evaluated with binding variables as parameters . In a preferred embodiment, the resulting XML document generation step comprises the steps of: (i) recursively traversing DTD constructs from a root element; and (ii) associating with binding variables after one of resolving binding functions and evaluating XML queries, until reaching a leaf construct, where a partial XML result is obtained by evaluating associated value functions. The resulting XML document is preferably composed during a traversal returning stage by adding XML tags enclosing the partial XML result. As will be explained below, the methodology of the invention preferably makes use of the DTD Source Annotation (DTDSA) method described in U.S. Serial No. 09/466,627 (attorney docket no. YOR9-1999-0429) filed , on December 17, 1999 and entitled "Method and Apparatus for Converting Between Data Sets and XML Documents,". A copy has been placed on the file. However, it is to be understood that the invention is not limited to the DTDSA mechanism. That is, other mechanisms or methods can be used. By way of example only, the IBM DB2 extender (IBM Corporation of Armonk, NY) , which saves the mapping information connecting DTD and a DB2 database in a separate file, may be employed. In a further aspect, the invention provides an apparatus for processing one or more extensible Markup Language (XML) queries, the method comprising the steps of: means for generating a mapping construct which maps a predetermined document type definition (DTD) to one or more data sources to be accessed in response to the one or more XML queries; means for evaluating the one or more XML queries in accordance with the mapping construct; and means for generating an XML document resulting from the query evaluation wherein the resulting XML document conforms to the predetermined DTD. In a yet further aspect, the invention provides an article of manufacture for processing one or more extensible Markup Language (XML) queries, comprising a machine readable medium containing one or more programs which when executed implement the steps of : generating a mapping construct which maps a predetermined document type definition (DTD) to one or more data sources to be accessed in response to the one or more XML queries; evaluating the one or more XML queries in accordance with the mapping construct; and generating an XML document resulting from the query evaluation wherein the resulting XML document conforms to the predetermined DTD. In a yet further aspect, the invention provides a computer-based apparatus for processing one or more extensible Markup Language (XML) queries, the apparatus comprising: a document retrieval engine responsive to the one or more XML queries and to a predetermined mapping construct which maps a predetermined document type definition (DTD) to one or more data sources to be accessed in response to the one or more XML queries, wherein the document retrieval engine is operative to (i) evaluate the one or more XML queries in accordance with the mapping construct; and (ii) generate an XML document resulting from the query evaluation, wherein the resulting XML document conforms to the predetermined DTD. The following are some examples of advantages provided by the universal output constructor, for XML queries, of the preferred embodiment. The user is able to choose an arbitrary DTD and to present the query output using that DTD. It is possible to use XPath or any other XML query language that the user chooses as the query pattern matching mechanism. The preferred embodiment allows multiple queries of different or same query languages or expressions to be naturally integrated and produce a single output XML document. The aforementioned queries can be to correlated. XML queries can be integrated with other data query or access mechanisms (e.g., Structured Query Language or SQL) to produce a single XML output document. The aforementioned XML queries and other data queries or access commands can be correlated. Brief Description of the Drawings A preferred embodiment of the present invention will now be described by way of example only and with reference to the following drawings : FIG. 1 is a block diagram illustrating the current XML query languages ; FIG. 2 is a block diagram illustrating a universal output constructor methodology for XML queries according to an embodiment of the present invention; FIGs . 3A and 3B are flow diagrams illustrating an algorithm for generating XML using DTDSA with queries in accordance with a preferred embodiment of the present invention; FIG. 4 is a diagram illustrating an association and distribution of variables in a DTDSA in accordance with a preferred embodiment of the present invention; FIG. 5 is a block diagram illustrating a hardware implementation suitable for employing a universal output constructor for XML queries according to an embodiment of the present invention; FIG. 6A is a diagram illustrating an example of a relational schema; FIG. 6B is a diagram illustrating an example of a DTD; FIG. 6C is a diagram illustrating a DTD annotated in accordance with a preferred mapping language; FIG. 6D is a diagram illustrating a directed acyclic graph specifically related to the example of FIGs. 6A, 6B and 6C and in accordance with a preferred embodiment of the present invention; and FIG. 6E is a diagram illustrating a retrieved XML document for the example depicted in FIGs. 6A, 6B, C and 6D and in accordance with a preferred embodiment of the present invention. Detailed Description of Preferred Embodiments Many concepts and constructs are used in the XML specification. However, some of them are implicitly references but not clearly defined, some others are used without being given a name. To facilitate discussion, these concepts and constructs are defined or given names, particularly, in the table below. In the column "Name given in," if the value is "previous work," that means the concept is used in previous work, for example, in accordance with the DTDSA mechanism described in the above-referenced U.S. Serial No. 09/466,627, but not defined in the DTD specification. If the value is "XML Spec," that means the concept is referenced, sometimes appears in a production rule, but is not explicitly defined in the DTD specification. Some of the terms are defined in a recursive manner, and each term may have an abbreviation enclosed by parentheses. In addition, column variable is a variable whose value is a column identity. Row variable is a variable whose value is a row of a table. A row variable is defined on a particular table, and can only have a row of that table as its value. Vector variable is a variable whose value is a list of objects, including values (or scalars) , variables, and other vectors, enclosed by "<" and ">", e.g., v=<100, <1, "ab" , 10>, x> . A detailed description of the invention in accordance with a preferred embodiment will now follow. Such descriptions will illustrate the various methods and apparatus of the invention for query and access of data from various data sources as integrated XML documents, for guaranteeing that the query outputs conform to the DTD of users' choice, and for generating XML documents based on the combination of different XML queries . As mentioned above, a preferred implementation for the mapping between DTD and relational schema is a DTD source annotation (DTDSA) , as described in the above-referenced U.S. Serial No. 09/466,627. In other words, the mapping between DTD and relational schema is encoded inside the DTD as annotations. The binding and value specifications are defined immediately following the DTD constructs which they are associated with. The method to establish mapping between DTD and underlying data is by associating a value specification with each #PCDATA, attribute definition, and choice list, associating a binding specification with each DTD construct ended with a trailing repetition symbol, and optionally associating binding specifications with other DTD constructs. A value specification is a parameterized formula containing variables, which, when a data object is substituted for each variable in it, produces a text value. A binding specification is a variable and expression pair. The expression can be a list of data objects, a formula that identifies a list of data objects, or a parameterized formula containing variables, which, when a data object is substituted for each variable in it, produces a list of data objects. A more detailed description of the DTDSA mechanism that is used in a preferred embodiment of the present invention is provided below in a section entitled "DTDSA Mapping" . (a) List producing function L( ) A function L(XQ) takes the output of an XML query, XQ, and returns the result of the filtering step of the XQ in a list. Assume that XQ has n filtering variables a 4 for i=l,...,n, and returns k lists { n , a 12 , •-., m }, {a 21 , a 22 , ..., a 2n } , ... , {a kl , a k2 , ... ΆAS . L(XQ) returns a list of vectors : { (an , a 12 , . . . , a ln ) , va 21 , a 22 , . . . a 2rι ) , . . . (ai d , a k2 , . . . a kri ) } If XQ uses scalar-based filtering, each ij is a scalar. If XQ uses subtree-based filtering, each a^ is a subtree. (b) Binding specifications The usage and semantics for binding specification is the same for XML query languages using either scalar or subtree-based filtering. Given a DTD and set of XML queries, it is possible to form a DTDSA that constructs a valid XML document using the data selected, i.e., at the filtering step, of the queries as follows. The filtering step of an XML query is associated to a binding variable to form a binding specification as follows: ::b:=L(XQ) where XQ is the XML query, b is the binding variable, and t for i=l, ...,n are filtering variables in XQ. The semantics are as follows: This list of values (vectors) returned by L(XQ) is associated with b using the DTDSA binding specification semantics described herein, i.e., the values are bound to b in turn, one for each instantiation of the annotated DTD construct. The values bound to b can be used in other binding specifications or value specifications. The following notation for the references to b is used herein: b refers to the whole vector (an, a 12 , ...a in ) , and b.a refers to the 'th field of the current vector bound to b. If the current vector is the ith in the list returned by L (XQ) , then b.aj = ^ . (c) XML queries using scalar-based filtering The usage and semantics of value specifications for XML queries using scalar-based filtering is the same as in the original DTDSA definition described herein. For binding specifications, the usage can include single XML query, multiple XML queries (correlated or uncorrelated), and non-XML queries. 1. One XML query construction: XQ is used as the binding function of a binding specification associated with the root element, each DTD construct such as #PCDATA, choice list, CDATA or enumerate type is annotated by a value specification which is either a b.ai, or a function on b.ai. 2. Multiple non-correlated XML query construction: Each XML query is used as the binding function of a binding specification, the binding specification of the functions. 3. Multiple correlated XML query construction: Each XML query is used as the binding function of a binding specification, the binding specification of the functions. The input parameter of an XML query may be of the form b.ai where b is the binding variable of another binding specification. 4. Construction for multiple correlated and uncorrelated XML and non-XML queries: Same as pure XML query cases, but some query can be non-XML queries. (d) XML queries using subtree-based filtering The syntax and semantics of the binding specification remains the same . : :b:=L(XQ(C, xs) ) where b is the binding variable, XQ is an XML query function, C is an XML query scope, and xs is the query (filtering) string. Note L(XQ) in this case returns { (a u , a 12 , ..., m), (a 21 , a 22 , ...a 2n ) , ... (a* ! , a k2 , ... a^.) }, where each a i:j is a subtree, and b is bound to a list of vectors of subtrees in turn. Let f ( ) be a function that takes references to one or more binding variables as input, and returns a subtree. Let y = f(b x , b 2 , ...b , where bi, for i=l, ...m, are references to binding variables. For example, y may (e) Using binding variables in value specifications Two types of functions may appear in value specifications: i. g(y) and h(b) , where g( ) and h( ) each returns a scalar value, ii. XQ(y, xs) and XQ(b, xs) where XQ( ) is an XML query and xs is some query string. A value specification of the form ":g(y)" or ":h(b)" annotates a #pcdata, choice list, cdata, or enumerate type, and provide value for the annotated construct . A value specification of the form ":XQ(y, xs) " or ":XQ(b, xs) " annotates an element E. The subtree ST, returned by XQ, is used as an instance of E in the final XML document constructed by the methodology of the preferred embodiment . The present invention preferably provides two types of policies for using ST as an instance of element E: 1. Test policy: If ST conforms to the portion of DTD described by E and its descendants, ST is accepted as an instance of E. Otherwise, it is rejected, and either some default value is used for the instance, or the query output construction process is aborted. 2. Transform policy: If ST conforms to the portion of DTD described by E and its descendants, ST is accepted as an instance of E. Otherwise, some transformation algorithm is used to transform ST into ST' which conforms to E. (f) Using binding variables in other binding specifications Binding variables bound to XML query outputs may be used in other binding specifications as follows: : X:=L(XQ(b, xs) ) , or : X:=L(XQ(f (b) , xs) ) , or : X:=L(XQ({f 1 (b 1 ) , f 2 (b 2 ) , ... f m (b } , xs) ) where xs is a query (filtering) string, b, and bi for i=l, ..., m are binding variables f, and ft for i=l,...,m, are functions that can take a list of subtrees and return a subtree . (g) Using cascade binding for nested .filtering/construction Most XML query languages allow construction and filtering stages to be recursively defined. Let Fi Ci F 2 C 2 ... F n C n represent a recursively defined query, where Fi is the ith filtering stage and Ci is the ith construction stage, for i = 1, 2, ... , n. Assume that Fi defines a l , a i2 , ... , F 2 defines a 2i , a 22 , ... , and F n defines a n ι, a n2 , ... , and a ± j may be used or referred in F k , for k > i, and in C k , for k > i. It is possible to have the following cascade binding: where BF t is binding functions, for i = l, 2, ... , n, and BFi returns (defines) <a n , a 12 , ... >, BF 2 returns <a 2i , a 22 , ... >, BF n returns <a nl , a n2 , ... >. Also i.aij may be a parameter of BF k , for k > i. Referring now to the drawings in which like numerals represent the same or similar elements and initially to FIG. 1, a block diagram of the three stages of general XML query languages is depicted. The first stage is the scoping that decides the domain of the query, indicated as block 140. The second stage is the filtering or selection that chooses data to participate in the query, indicated by block 130. The third stage is the construction that builds the XML output from the chosen data, indicated as block 120. These three stages can be recursively defined, as indicated by the arrow 110, to form a nested loop iteration. The result of the three stages is a well-formed XML document. FIG. 2 is a block diagram illustrating a universal output constructor methodology for XML queries according to an embodiment of the present invention. As shown, a DTD 200 can be annotated with different expressions from different query languages, to form a mapping construct DTDSA 312 that guides the access and translation engine 305 to retrieve data from different types of data sources. The user is able to provide input parameters 310 to the engine, and receive as output a valid XML document 315. The mapping constructs can be written in the original DTDSA mapping expressions 240, the query languages that include the scoping (block 212) and filtering (block 210) stages such as XQL 230, the query languages that include an extra construction stage such as XML-QL 220, and a mixture of all of the above expressions or languages. If the query language includes a construction stage, the third stage shown as the construction stage 120 in FIG. 1 will be ignored. The query languages 220 and 230 may describe the mapping constructs for accessing XML repositories 225 and 235, while the original DTDSA mapping expression 240 may describe those for the relational database systems 245. The original DTDSA mapping expressions include value specifications and binding specifications, for example, as are illustrated and described below in the context of FIGs. 6A through 6E . It is to be appreciated that the universal output constructor is preferably comprised of the engine 305 and the mapping framework DTDSA 312. However, in an alternative embodiment, the universal output constructor may be considered as just comprising the engine 305 which has access to the DTDSA 312. FIGs. 3A and 3B depict a method for generating XML documents based on the new mappings that are included in the DTDSA in accordance with a preferred embodiment . The method makes use of the DTDSA method described above with a modification for evaluating XML queries in a binding specification, and assigning a result to the binding variables, as shown in block 350. It should be understood that the elements shown in FIG. 3B may be implemented in various forms of hardware, software or combinations thereof. Preferably, these elements are implemented in software on one or more appropriately programmed general purpose digital computers having a processor and memory and input/output interfaces, an example of which is shown in FIG. 5. In any case, FIG. 3A illustrates a block diagram representing the XML composition algorithm using DTDSA. A document retrieval and composition engine or algorithm 305 receives input parameter name and value pairs 310, e.g., (A=l, B=100) , and generates a return XML document 315 based on the provided DTDSA 312. An internal flow diagram of the algorithm 305 is shown in FIG. 3B. Initially, the algorithm parses the DTDSA 312 into an internal format, e.g., a directed acyclic graph, which is easy to manipulate, and prepares the input parameters into environmental variables, as depicted in block 320 (i.e., read in DTDSA as a graph structure; accept input parameters and add into ENV) . The algorithm then performs a breadth first search (BFS) traversal on the internal DTDSA structure, using a first-in-first-out queue to keep track of the set of structure nodes visited. The BFS traversal includes a standard procedure which sets up initial values (add document root and initial environmental variables ENV into queue tail) for the queue (block 325) , repeats fetching the queue until the queue is empty (block 330) , and for every node and environmental variables fetched (block 335 - retrieve a node and ENV from queue head) , performs operations (block 340 as will be described below) to generate partial XML components and adds all the children nodes, if any, and new environmental variables/values to the queue (block 345) . As shown in block 340, the operations for a visited node, denoting a data type or attribute type, include: (l) resolving unbound variables which are associated with the data type or attribute, and defined in binding or value specifications in the DTDSA, using the fetched environmental variables/values (the resolution of unbound variables may involve accessing data sources and a predefined function calculation) ; (2) evaluating XML queries of different query languages in the binding specification, and assigning a result to the binding variables (step 350) ; (3) generating partial XML components based on current DTDSA node name (ENAME) as the tag, and the resolved content as the value or attribute; (4) adding the newly created variable/value pairs into the environmental variables (ENV) . Referring now to FIG. 4, the association and distribution of variables in a DTDSA is illustrated. As shown, the DTDSA in a particular illustration may be represented as: <iELEMENT PO (buyer, seller) :: x:=XML-QL/XQL/XPath/original map> <! ELEMENT buyer (name, addr) > <! ELEMENT name (#PCDATA : x.a)> <! ELEMENT addr (#PCDATA : X.b)> where v x' is the binding variable, 'a' and b' are the filter variables in the XML query and ( a' and λ b' are referenced in DTDSA as 'x.a' and 'x.b, ' respectively. The association relates to the binding specification in that the query results are bound to a variable, say 'x' as referenced by numeral 410. The distribution relates to the usages of the bound variables in the DTDSA. For example, v x.a' at reference numeral 420 retrieves the value of column 'a' in a row bound by 'x' for a relational database, or the content of tag 'a' in an XML component bound by x x' for an XML repository. FIG. 5 s a block diagram illustrating a hardware implementation suitable for employing a universal output constructor for XML queries according to an embodiment of the present invention. It is to be understood that the universal output constructor for XML queries, namely, the engine 305 and, preferably, the DTDSA 312 (FIGs. 2 and 3), may be implemented on one such computer system, or on more than one separate such computer system, e.g., in a client-server relationship. For example, the engine 305 can be run as a server site application written in Java™ Servlet (Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries) , or a client site application executed by an Internet browser . As shown, the computer system is implemented in accordance with a processor 502, a memory 504 and I/O devices 506. It is to be appreciated that the term "processor" as used herein is intended to include any processing device, such as, for example, one that includes a CPU (central processing unit) and/or other processing circuitry. The term "memory" as used herein is intended to include memory associated with a processor or CPU, such as, for example, RAM, ROM, a fixed memory device (e.g., hard drive), a removable memory device (e.g.. diskette), flash memory, etc. In addition, the term "input/output devices" or "I/O devices" as used herein is intended to include, for example, one or mo.re input devices, e.g. s ' keyboard, for entering data to the processing unit, and/or one or more output devices, e.g., CRT display and/or printer, for presenting results associated with the processing unit. It is also to be understood that the term "processor" may refer to more than one processing device and that various elements associated with a processing device may be shared by other processing devices. Accordingly, software components including instructions or code for performing the methodologies of the preferred embodiment, as described herein, may be stored in one or more of the associated memory devices (e.g., ROM, fixed or removable memory) and, when ready to be utilized, loaded in part or in whole (e.g., into RAM) and executed by a CPU. DTDSA Mapping As mentioned above, a preferred implementation for the mapping between DTD and a relational schema is a DTD source annotation (DTDSA) , as described in the above-referenced U.S. Serial No. 09/466,627. The following is a detailed description of such a DTDSA mechanism. FIG. 6A illustratively includes four relational tables, also known as a relational schema, purchase order ("PO") 1305, company 1310, lineitem 1315, and product 1320. Table 1305 has three columns, purchase order identification ("POID"), buyer, and seller. The rows of the table have numerical index values pointing to values for the columns. Thus purchase order number 100 is associated with buyer 20 and seller 10. Table 1310 has three columns: company identification ("COID"), name, and address ("ADDR") . The rows associate numerical values with actual company names and addresses. Thus the numerical value 10 is associated with the company IBM, having an address in New York, and the numerical value 20 is associated with the company Citibank, also having an address in New York. Table 1315 has three columns: POID, product identification ("PRODID") , and amount. The rows, 1330 and 1335, associate purchase order identification numbers with product identification numbers and quantities. In the figure, purchase order 100 is associated with two product identifications, 35678 and 35694, of which 20k and 100k are ordered respectively. Table 1320 has three columns, PRODID, name, and desc. (description). The rows associate product identification 35678 with a "THINKPAD™" and product identification 35694 with a server. Arrows in FIG. 6A illustrate foreign key relations among various fields. For example, the record 1325 in PO table with POID=100 is related via arrows 1340 and 1345 to two records 1330, 1335 in the lineitem table 1315 with POID=100. Similarly, records 1330 and 1335 are associated via arrow 1350 to records 1355 and 1360. FIG. 6B shows an example of a Document Type Definition (DTD) . As explained above, XML makes use of DTDs to specify documents. DTDs are very flexible and can specify any number of different documents. FIG. 6B shows only one simple example, in which a purchase order is specified. Line 1301 shows the definition of the variable PO. In a tree-like fashion, the definition incorporates child definitions, i.e., "id" defined at line 1302, "buyer" defined at line 1303, "seller" defined at line 1304, and "lineitem" defined at line 1307. The asterisk after "lineitem" at 1320 indicates that this feature may be repeated any number of times in the purchase order. The definitions of "id" 1302, "address" 1311, "prodname" 1308, and "amount" 1310 use the #PCDATA command to get data directly from a data storage device. The definitions of "buyer" and "seller" have attribute lists at 1323 and 1324. The definition of lineitem, also incorporates child definitions, "prodname" at line 1308 and "amount" at line 1310. FIG. 6B is to be annotated based on the relational schema in FIG. 6A, and the resulting annotated DTD (DTDSA) is illustrated in FIG. 6C. FIG. 6C shows a DTD annotated in accordance with the preferred mapping language, i.e., a DTDSA. The preferred mapping language includes two types of constructs: the binding specification and the value specificatio . FIG. 6D shows a directed acyclic graph specifically related to the example of FIGs. 6A, 6B and 6C. A sequence of resolutions occurs based on the BFS traversal order. The resolutions at numerals 1905, 1910, 1915, 1920, 1925, 1935, and 1945 of FIG. 6D correspond to the binding/value specifications at numerals 1505, 1510, 1515, 1520, 1525, 1535, and 1545 of FIG. 6C, respectively. The resolution for the binding specification at numeral 1510 using x=100 involves table PO access with poid=100 and derives into a record <100, 20, 10> for r as shown in 1910. The binding specification in 1505 uses the record r to derive its third argument, PO. poid (r) , to 100, which is needed to resolution of w, i.e., row (linei tem, poid, 100) . Since there are two records in table linei tem with POID=100, as shown by numerals 1330 and 1335 in FIG. 6A, w is assigned the two records as shown at numeral 1905. Such binding can be used to derive multiple occurrence of a data type along the edge marked with "*" or "+" as shown at numeral 1902. The two records for variable w can be used to derive two XML components lineitem as shown at numeral 1925. Attribute values with value specification can also be similarly derived. For example, as shown at numeral 1920, the attribute name with a "<-)" prefix of data type buyer can have a resolved value s from deriving the binding specification at numeral 1535 using r as shown at numeral 1935. FIG. 6E shows the retrieved XML document for the example depicted in FIGs. 6A, 6B, 6C and 6D. Based on the input x=100, the document is a PO with id 100. There are two line items retrieved and composed as shown at numerals 2010 and 2015. Attributes are also illustrated as shown at numerals 2005 and 2010.

Claims: CLAIMS 1. A method of processing one or more extensible Markup Language (XML) queries, the method comprising the steps of: generating a mapping construct which maps a predetermined document type definition (DTD) to one or more data sources to be accessed in response to the one or more XML queries; evaluating the one or more XML queries in accordance with the mapping construct; and generating an XML document resulting from the query evaluation wherein the resulting XML document conforms to the predetermined DTD. 2. The method of claim 1, wherein the mapping construct includes a binding specification and wherein the one or more XML queries are bound to one or more binding variables . 3. The method of claim 2 wherein the one or more XML queries are evaluated in accordance with the binding specification of the mapping construct and the method further comprises the step of assigning the evaluation result to the one or more binding variables . 4. The method of any preceding claim, wherein the one or more XML queries are written in one or more XML query languages . 5. The method of any preceding claim, wherein the resulting XML document is a combination of more than one XML query associated with one or more query languages. 6. The method of any of claims 1 to 4, wherein the resulting XML document is a combination of one or more XML queries and one or more non-XML queries . 7. The method of any preceding claim, wherein the DTD is specified by a user. 8. The method of claim 3, wherein the mapping construct generation step comprises the steps of: determining suitable DTD constructs; binding the constructs to variables; associating the variables with a partial XML result obtained from scoping and filtering stages of the XML query; and distributing the variables to suitable DTD constructs with value functions . 9. The method of claim 8, further comprising the step of accepting scalar-based results from the scoping and filtering stages. 10. The method, of claim 8 or 9, further comprising the step of accepting subtree-based results from the scoping and filtering stages. 11. The method of any of claims 8 to 10, further comprising the step of allowing the bindings to be used as parameters in at least one of value generation functions and other binding functions . 12. The method of any of claims 8 to 11, further comprising the step of resolving a nested or recursive filtering query construct with sequential cascade binding constructs. 13. The method of claim 3, wherein the query evaluation step comprises the step of combining different parsing and evaluating mechanisms for evaluating XML queries from different XML query languages . 14. The method of claim 13, further comprising the step of allowing binding variables to be used in one or more XML queries of different query languages. 15. The method in claim 13 or 14, further comprising the step of evaluating one or more XML queries of different query languages with binding variables as parameters. 16. The method of claim 3 , wherein the resulting XML document generation step comprises the steps of: recursively traversing DTD constructs from a root element; and associating with binding variables after one of resolving binding functions and evaluating XML queries, until reaching a leaf construct, where a partial XML result is obtained by evaluating associated value functions . 17. The method of claim 16, wherein the resulting XML document is composed during a traversal returning stage by adding XML tags enclosing the partial XML ' result. 18. Apparatus for processing one or more extensible Markup Language (XML) queries, the method comprising the steps of: means for generating a mapping construct which maps a predetermined document type definition (DTD) to one or more data sources to be accessed in response to the one or more XML queries; means for evaluating the one or more XML queries in accordance with the mapping construct; and means for generating an XML document resulting from the query evaluation wherein the resulting XML document conforms to the predetermined DTD. 19. The apparatus of claim 18, wherein the mapping construct includes a binding specification and. wherein the one or more XML queries are bound to one or more binding variables . 20. The method of claim 19, wherein the one or more XML queries are evaluated in accordance with the binding specification of the mapping construct and the apparatus further comprises means for assigning the evaluation result to the one or more binding variables. 21. The apparatus of claim 18, 19 or 20, wherein the one or more XML queries are written in one or mere XML query languages . 22. The apparatus of claim 18, 19, 20 or 21 wherein the resulting XML document is a combination of more than one XML query associated with one or more query languages . 23. The apparatus of any of claims 18 to 21, wherein the resulting XML document is a combination of one or more XML queries and one or more non-XML queries . 2 . The apparatus of any of claims 18 to 23 , wherein the DTD is specified by a user. 25. The apparatus of claim 20, wherein the mapping construct generation operation comprises: (i) determining suitable DTD constructs; (ii) binding the constructs to variables; (iii) associating the variables with a partial XML result obtained from scoping and filtering stages of the XML query; and (iv) distributing the variables to suitable DTD constructs with value functions . 26. The apparatus of claim 25, wherein the at least one processor is further operative to accept scalar-based results from the scoping and filtering stages. 27. The apparatus of claim 25 or 26, wherein the at least one processor is further operative to accept subtree-based results from the scoping and filtering stages. 28. The apparatus of any of claims 25 to 27, wherein the at least one processor is further operative to allow the bindings to be used as parameters in at least one of value generation functions and other binding functions . 29. The apparatus of any of claims 25 to 28, wherein the at least one processor is further operative to resolve a nested or recursive filtering query construct with sequential casuade. binding constructs. 30. The apparatus of claim 20., wherein the query evaluation operation comprises combining different parsing and evaluating mechanisms for evaluating XML queries from different XML query languages . 31. The apparatus of claim 30, wherein the at least one processor is further operative to allow binding variables to be used in one or more XML queries of different query languages . 32. The apparatus in clairrr30 or 31, wherein the at least one processor is further operative to evaluate one or more XML queries of different query languages with binding variables as parameters. 33. The apparatus of claim 3, wherein the resulting XML document generation operation comprises: (i) recursively traversing DTD constructs from a root element; and (ii) associating with binding variables after one of resolving binding functions and evaluating XML queries, until reaching a leaf construct, where a partial XML result is obtained by evaluating associated value functions. 34. The apparatus of claim 33, wherein the resulting XML document is composed during a traversal returning stage by adding XML tags enclosing the partial XML result. 35. An article of manufacture for processing one or more extensible Markup Language (XML) queries, comprising a machine readable medium containing one or more programs which when executed implement the steps of: generating a mapping construct which maps a predetermined document type definition (DTD) to one or more data sources to be accessed in response to the one or more XML queries ; evaluating the one or more XML queries in accordance with the mapping construct; and generating an XML document resulting from the query evaluation wherein the resulting XML document conforms to the predetermined DTD. 36. Computer-based apparatus for processing one or more extensible Markup Language (XML) queries, the apparatus comprising: a document retrieval engine responsive to the one or more XML queries and to a predetermined mapping construct which maps a predetermined document type definition (DTD) to one or more data sources to be accessed in response to the one or more XML queries, wherein the document retrieval engine is operative to (i) evaluate the one or more XML queries in accordance with the mapping construct; and (ii) generate an XML document resulting from the query evaluation, wherein the resulting XML document conforms to the predetermined DTD.

Inventors: CHEN SHYH-KWEI, LO MING-LING, CHEN, SHYH-KWEI, LO, MING-LING
Applicants: IBM, IBM UK, IBM UNITED KINGDOM LIMITED, INTERNATIONAL BUSINESS MACHINES CORPORATION
Application year: 2001
Main classification: G06F17
IPC codes: G06F17