Abstract:
In an automated fashion, a collection of XML documents are traversed and statistical data is generated describing hierarchical relationships of the elements, the elements data types and values. Based the analysis, an XML schema is derived such that the collection of XML documents conforms to the schema to a certain degree.

Description:
RELATED APPLICATIONS 
       [0001]    The present application is related to U.S. patent application Ser. No. 10/909,985, A Mechanism For Computing Structural Summaries Of XML Document Collections In A Database System, filed on Jul. 18, 2005 by Ravi Murthy, et al., the entire content of which are herein incorporated by reference. 
     
    
     FIELD OF THE INVENTION 
       [0002]    The present invention relates to processing XML data. 
       BACKGROUND OF THE INVENTION 
       [0003]    The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in this section. 
         [0004]    The Extensible Markup Language (XML) is the standard for data and documents that is finding wide acceptance in the computer industry. XML describes and provides structure to a body of data, such as a file or data packet. The XML standard provides for tags that delimit sections of a XML entity referred to as XML elements. The following XML document A is provided to illustrate XML. 
         [0000]    
       
         
               
             
               
               
             
           
               
                   
               
               
                 XML document A 
               
               
                   
               
             
             
               
                   
               
             
          
           
               
                   
                  &lt;a c=“foo”&gt; 
               
               
                   
                 &lt;b&gt;5&lt;/b&gt; 
               
               
                   
                   &lt;d&gt;10&lt;/d&gt; 
               
               
                   
                  &lt;/a&gt; 
               
               
                   
                   
               
             
          
         
       
     
         [0005]    XML elements are delimited by a start tag and a corresponding end tag. For example, segment A contains the start tag &lt;b&gt; and the end tag &lt;/b&gt; to delimit an element. The data between the elements is referred to as the element&#39;s content. 
         [0006]    An element has a name and is referred to herein by its name. The name of the element delimited by &lt;b&gt; and the end tag &lt;/b&gt; is b and is thus referred to herein as element b or just b. 
         [0007]    An element&#39;s content may include the elements value, one or more attributes and one or more elements. Such an element is referred to as a complex element. Element a is a complex element, and contains two elements b and d. An element that is contained by another element is referred to as a descendant of that element. Thus, elements b and d are descendants of element a. An element&#39;s attributes are also referred to as being contained by the element. An element that contains no other elements is referred to as a simple or leaf element. 
         [0008]    An attribute is a name value pair. Element a has attribute c, which has the value ‘foo’. 
         [0009]    Element b has the value 5 and element d has the value 10. Element a does not have a value. 
         [0010]    By defining elements that contain attributes and descendant elements, a XML document defines a hierarchical tree relationship between the elements, descendant elements, and attributes of the elements. 
       Node Tree Model 
       [0011]    XML documents are represented as a hierarchy of nodes that reflects the XML document&#39;s hierarchical nature. A hierarchy of nodes is composed of nodes at multiple levels. The nodes at each level are each linked to one or more nodes at a different level. Each node at a level below the top level is a child node of one or more of the parent nodes at the level above. Nodes at the same level are sibling nodes. 
         [0012]    In a tree hierarchy or node tree, each child node has only one parent node, but a parent node may have multiple child nodes. A node that has no parent node linked to it is the root node, and a node that has no child nodes linked to it is a leaf node. A tree hierarchy has a single root node. In a node tree that represents a XML document, a node can correspond to an element, and the child nodes of the node correspond to an attribute or another element contained in the element. 
         [0013]    For convenience of expression, an element and attribute of a XML document are referred to as the node that corresponds to that element or attribute within the node tree that represents the XML document. Thus, referring to 5 as the value of node b is just a way of expressing that the value of the element b is 5. 
       XML Schemas 
       [0014]    Information about the structure of specific types of XML documents may be specified in documents referred to as “XML schemas”. For example, the XML schema for a particular type of XML document contains declarations that specify the names for the elements contained in that type of XML document, the hierarchical relationship between the elements contained in that type of XML document, and the data type of values contained in that particular type of XML document. Standards governing XML schemas include: XML Schema, Part 0, Part 1, Part 2, W3C Recommendation, 2 May 2001, the contents of which are incorporated herein by reference; XML Schema Part 1: Structures, Second Edition, W3C Recommendation 28 Oct. 2004, the contents of which are incorporated herein by reference; XML Schema 1.1 Part 2: Datatypes, W3C Working Draft 17 Feb. 2006, the contents of which are incorporated herein by reference; and XML Schema Part 2: Datatypes Second Edition, W3C Recommendation 28 Oct. 2004, the contents of which incorporated herein by reference. XML Schemas as described in this document are not restricted to W3C XML Schemas but include any other mechanisms for describing the structural and/or typing information of XML documents, for example, Relax NG. 
         [0015]    Often, for large bodies of XML documents, no XML schema document has been developed or engineered by developers. Described herein are approaches for automatically determining an XML schema to which a collection of XML documents may conform to varying degrees. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0016]    The present invention is illustrated by way of example, and not by way of limitation, in the figures of the accompanying drawings and in which like reference numerals refer to similar elements and in which: 
           [0017]      FIG. 1  is a flow chart of an approach for deriving an XML schema from a collection of XML documents. 
           [0018]      FIG. 2  is a block diagram of a computer system that may used to implement an embodiment of the present invention. 
       
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
       [0019]    A method and apparatus for presenting structural and typing information about XML documents is described. In the following description, for the purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the present invention. It will be apparent, however, that the present invention may be practiced without these specific details. In other instances, well-known structures and devices are shown in block diagram form in order to avoid unnecessarily obscuring the present invention. 
         [0020]    Described herein are approaches to derive “optimal” XML schemas from XML document collections. There are various aspects as to what constitutes an “optimal” XML schema, which include: 
         [0021]    (a) how precise or specific is the XML schema—the more explicit structure defined, and more specific datatypes defined other than string, the better the XML schema, 
         [0022]    (b) how many documents from the collection conform to the XML schema, the higher the number, the better the XML schema, 
         [0023]    (c) in the case of documents that do not conform to the XML schema, how are those documents different and how many differences are there. 
         [0024]    A goal of deriving a XML schema is that the XML schema defines as much structural, data types, and facets or value constraints of the date types as plausible to describe XML documents in the collection. Data types include those explicitly defined by XML standards, including for example, integer, double, dateTime, or anyType. Facets include constraining facets, such as defined by XML Schema 1.1 Part 2, e.g., range of acceptable values (minimum and maximum values). 
       Two-Pass Approach to Automatically Deriving XML Schema 
       [0025]      FIG. 1  depicts a two pass approach for deriving a XML schema of a collection of documents. Referring to  FIG. 1 , in pass  1 , all the documents in the collection are traversed and statistical data (“statistics”) is generated describing data type relevant properties of the elements, which may include, for an element, the data types and/or information about different values encountered for that element. Also, for a complex element, the number of its occurrences is tracked. In addition, the number of occurrences of each of its children and/or descendants is also tracked. Information about values may include a summary of the values encountered, such as the specific values encountered and for each value, the number of occurrences. 
         [0026]    For example, during pass  1 , the statistics for a complex element A are as follows. 
         [0000]    
       
         
               
               
             
           
               
                   
                   
               
             
             
               
                   
                 &lt;A&gt; --- [100] 
               
               
                   
                  &lt;B&gt; --- [100] 
               
               
                   
                  &lt;C&gt; --- [98] 
               
               
                   
                  &lt;foo&gt; --- [1] 
               
               
                   
                   
               
             
          
         
       
     
         [0027]    The above structural summary represents that complex element &lt;A&gt; has appeared  100  times in the collection. It has element &lt;B&gt; as a child in all 100 cases, element &lt;C&gt; as child in 98 cases, and element &lt;foo&gt; as a child in only 1 case. 
         [0028]    In pass  2 , the XML schema is derived based on examination and analysis of statistics along with an occurrence threshold. For example, the occurrence threshold is 5%. If an instance of a child element occurs in less than 5% of the instances of a complex element, then the child element is excluded from the derived XML schema. In this example, the derived XML schema for element &lt;A&gt; will include child elements &lt;B&gt; and &lt;C&gt;, but does not include &lt;foo&gt;. This ensures that a XML schema is not polluted by rare occurrences leading to overly complicated and/or large schemas. 
         [0029]    The above is an example of how the hierarchical structural relationship between elements is derived. However, elements have other properties which may be derived from statistics and defined by an XML schema. According to an embodiment, one or more data types and one or more of the following facets may be derived from an XML schema for an element. According to an embodiment, one or more of these properties may be associated with its&#39; own occurrence threshold that is applied when determining whether to define the property for an element. 
         [0030]    Datatype 
         [0031]    For simple elements, the occurrences of datatypes and/or particular values are tracked in pass  1 . For example, the statistics for scalar element &lt;age&gt; is as follows. 
         [0000]    
       
         
               
               
             
           
               
                   
                   
               
             
             
               
                   
                 &lt;age&gt; [#occurrences = 100] 
               
               
                   
                 -- integer [#occ = 99] 
               
               
                   
                 -- string [#occ = 1] 
               
               
                   
                   
               
             
          
         
       
     
         [0032]    In most instances of the element &lt;age&gt;, the element value is of the datatype integer, except in one case, where the element value is not an integer but is a string. Based on an occurrence threshold, it is assumed that the string value is an exception (e.g. a typo) and datatype for &lt;age&gt; is defined by the derived XML schema as an integer. 
         [0033]    Value Range 
         [0034]    During pass  2 , values tracked by statistics for an element may be limited to a range (or maximum and minimum values). For example, the statistics indicate that the maximum value for the element age is 110. The derived XML schema could define a constraining facet for &lt;age&gt; limiting the values for the element to a maximum value of 110. According to an embodiment, an occurrence threshold is applied such that values that meet the threshold are covered by the constraining facet. 
         [0035]    Value Enumeration 
         [0036]    The statistics generated may track the fact that an element is set to only a limited set of values. For example, for the element &lt;gender&gt;, the statistics indicate that the values are set to ‘M’ or ‘F’. The derived XML schema may define an enumeration value domain (i.e. set of values) limited to the values ‘M’ and ‘F. According to an embodiment, any value that occurs at least as frequently as the occurrence threshold is a value defined as being in the value domain. 
         [0037]    Character/String Pattern 
         [0038]    Examination of the statistics generated may track the fact that element values conform to a particular set of string patterns. For example, most of the values for the element &lt;account&gt; conform to pattern 3N″-“ 4 N” (a string of three digits and a string of four digits separated by a dash) or 7N (seven digits). These patterns together cover a threshold percentage of values, and the derived XML schema may be defined to constrain &lt;account&gt; to this pattern. 
         [0039]    The lists of facets that may be derived listed above are illustrative and should not be construed as limiting. 
       Incremental Refinement 
       [0040]    The statistics computed in the first pass may be stored persistently. As new documents are added to the collection, the derived XML schemas can be incrementally refined. The new documents may be traversed and statistics updated to reflect the structure and facets of the new documents. Next, the second pass is rerun based on the updated statistics, producing possibly a new version of the derived XML schema. 
       XML Schema Goodness Score. 
       [0041]    The system provides a “goodness” (or “conformity”) score for a derived XML schema. The score is based on the number of documents in the collection that conform to the derived XML schema versus the number of exceptions in the system. Based on this score, the occurrence threshold could be further adjusted and reconfigured. 
         [0042]    For example, the two pass approach may be implemented in software, and the frequency threshold may be configured by user input received by the software. If the occurrence threshold of 10% results in a poor score for the derived XML schema, the threshold can be decreased to 5% in an attempt to create a more encompassing XML schema. 
       HARDWARE OVERVIEW 
       [0043]      FIG. 2  is a block diagram that illustrates a computer system  200  upon which an embodiment of the invention may be implemented. Computer system  200  includes a bus  202  or other communication mechanism for communicating information, and a processor  204  coupled with bus  202  for processing information. Computer system  200  also includes a main memory  206 , such as a random access memory (RAM) or other dynamic storage device, coupled to bus  202  for storing information and instructions to be executed by processor  204 . Main memory  206  also may be used for storing temporary variables or other intermediate information during execution of instructions to be executed by processor  204 . Computer system  200  further includes a read only memory (ROM)  208  or other static storage device coupled to bus  202  for storing static information and instructions for processor  204 . A storage device  210 , such as a magnetic disk or optical disk, is provided and coupled to bus  202  for storing information and instructions. 
         [0044]    Computer system  200  may be coupled via bus  202  to a display  212 , such as a cathode ray tube (CRT), for displaying information to a computer user. An input device  214 , including alphanumeric and other keys, is coupled to bus  202  for communicating information and command selections to processor  204 . Another type of user input device is cursor control  216 , such as a mouse, a trackball, or cursor direction keys for communicating direction information and command selections to processor  204  and for controlling cursor movement on display  212 . This input device typically has two degrees of freedom in two axes, a first axis (e.g., x) and a second axis (e.g., y), that allows the device to specify positions in a plane. 
         [0045]    The invention is related to the use of computer system  200  for implementing the techniques described herein. According to one embodiment of the invention, those techniques are performed by computer system  200  in response to processor  204  executing one or more sequences of one or more instructions contained in main memory  206 . Such instructions may be read into main memory  206  from another computer-readable medium, such as storage device  210 . Execution of the sequences of instructions contained in main memory  206  causes processor  204  to perform the process steps described herein. In alternative embodiments, hard-wired circuitry may be used in place of or in combination with software instructions to implement the invention. Thus, embodiments of the invention are not limited to any specific combination of hardware circuitry and software. 
         [0046]    The term “computer-readable medium” as used herein refers to any medium that participates in providing instructions to processor  204  for execution. Such a medium may take many forms, including but not limited to, non-volatile media, volatile media, and transmission media. Non-volatile media includes, for example, optical or magnetic disks, such as storage device  210 . Volatile media includes dynamic memory, such as main memory  206 . Transmission media includes coaxial cables, copper wire and fiber optics, including the wires that comprise bus  202 . Transmission media can also take the form of acoustic or light waves, such as those generated during radio-wave and infra-red data communications. 
         [0047]    Common forms of computer-readable media include, for example, a floppy disk, a flexible disk, hard disk, magnetic tape, or any other magnetic medium, a CD-ROM, any other optical medium, punchcards, papertape, any other physical medium with patterns of holes, a RAM, a PROM, and EPROM, a FLASH-EPROM, any other memory chip or cartridge, a carrier wave as described hereinafter, or any other medium from which a computer can read. 
         [0048]    Various forms of computer readable media may be involved in carrying one or more sequences of one or more instructions to processor  204  for execution. For example, the instructions may initially be carried on a magnetic disk of a remote computer. The remote computer can load the instructions into its dynamic memory and send the instructions over a telephone line using a modem. A modem local to computer system  200  can receive the data on the telephone line and use an infra-red transmitter to convert the data to an infra-red signal. An infra-red detector can receive the data carried in the infra-red signal and appropriate circuitry can place the data on bus  202 . Bus  202  carries the data to main memory  206 , from which processor  204  retrieves and executes the instructions. The instructions received by main memory  206  may optionally be stored on storage device  210  either before or after execution by processor  204 . 
         [0049]    Computer system  200  also includes a communication interface  218  coupled to bus  202 . Communication interface  218  provides a two-way data communication coupling to a network link  220  that is connected to a local network  222 . For example, communication interface  218  may be an integrated services digital network (ISDN) card or a modem to provide a data communication connection to a corresponding type of telephone line. As another example, communication interface  218  may be a local area network (LAN) card to provide a data communication connection to a compatible LAN. Wireless links may also be implemented. In any such implementation, communication interface  218  sends and receives electrical, electromagnetic or optical signals that carry digital data streams representing various types of information. 
         [0050]    Network link  220  typically provides data communication through one or more networks to other data devices. For example, network link  220  may provide a connection through local network  222  to a host computer  224  or to data equipment operated by an Internet Service Provider (ISP)  226 . ISP  226  in turn provides data communication services through the world wide packet data communication network now commonly referred to as the “Internet”  228 . Local network  222  and Internet  228  both use electrical, electromagnetic or optical signals that carry digital data streams. The signals through the various networks and the signals on network link  220  and through communication interface  218 , which carry the digital data to and from computer system  200 , are exemplary forms of carrier waves transporting the information. 
         [0051]    Computer system  200  can send messages and receive data, including program code, through the network(s), network link  220  and communication interface  218 . In the Internet example, a server  230  might transmit a requested code for an application program through Internet  228 , ISP  226 , local network  222  and communication interface  218 . 
         [0052]    The received code may be executed by processor  204  as it is received, and/or stored in storage device  210 , or other non-volatile storage for later execution. In this manner, computer system  200  may obtain application code in the form of a carrier wave. 
         [0053]    In the foregoing specification, embodiments of the invention have been described with reference to numerous specific details that may vary from implementation to implementation. Thus, the sole and exclusive indicator of what is the invention, and is intended by the applicants to be the invention, is the set of claims that issue from this application, in the specific form in which such claims issue, including any subsequent correction. Any definitions expressly set forth herein for terms contained in such claims shall govern the meaning of such terms as used in the claims. Hence, no limitation, element, property, feature, advantage or attribute that is not expressly recited in a claim should limit the scope of such claim in any way. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.