1. Field of the Invention
The present invention relates to software. Specifically, this application relates to Internet related software.
2. Description of the Prior Art
Extensible Markup Language (XML) is a widely accepted standard for describing data. XML is a standard that allows an author/programmer, etc to describe and define data (i.e., type and structure) as part of the XML content (i.e., document, etc). Since XML content may describe data, any application that understands XML regardless of the applications programming language and platform has the ability to process the XML based content.
An XML parser is a software program that checks XML syntax and processes XML data so that it is available to applications. XML content can optionally reference another document or set of rules that define the structure of an XML document/content. This other document or set of rules is often referred to as a Schema. When an XML document references a Schema, some parsers (i.e., validating parsers) can read the Schema and check that the XML document adheres to the structure defined in the Schema. If the XML document adheres to the structure defined in the Schema, then the XML document is considered valid.
XML has become the industry standard for exchanging data across systems because of its flexibility and consistent syntax. A parser processes XML content. However, conventional XML parsing (i.e., processing by a parser) is slow. Once reason for the lack of performance (i.e., slow speed) is the use of general-purpose external parsers. These parsers process XML content into general-purpose data structures and then apply run-time analysis to rebind the data to application-specific structures. Extra space is consumed by the intermediate data structures (i.e., general purpose data structures) and extra time is spent creating and analyzing them. Moreover, it is labor intensive to write the conversion code that converts the general-purpose data structures to application-specific data structures required for final processing.
There are three broad types of conventional XML parsers: SAX (Simple API for XML) parsers, DOM (Document Object Model) parsers, and data-binding parsers. Each type of XML parser defines a standard for accessing and manipulating XML documents. However, for various reasons, each of these parsers is labor intensive to implement.
SAX (Simple API for XML) uses an event-driven model to process XML content. A SAX parser initiates a series of events as it reads an XML document from beginning to end. The events are passed to event handlers, which provide access to the content in the document. Some of these event handlers check the syntax of the XML document (i.e., syntactic events). In conventional SAX parsers, a developer has to program the event handlers (i.e., developer-written events). In addition, a SAX parser invokes developer-written callback routines to manage the syntactic events. A callback routine is a routine that is executed as part of the operation of some other routine.
There are many shortcomings to conventional SAX parsers. First, developers have to manually program the event handlers and the callback routines. In addition, conventional SAX parsers are slow for various reasons. For example, some SAX parsers scan the XML input more than once, other SAX parsers perform serial processing of the XML document, and many SAX parsers build a number of intermediate data structures to facilitate the parsing of the XML document.
At the other extreme, DOM parsers first parse an XML document to build an internal, tree-shaped representation of the XML document. The developer then uses an Application Programmer Interface (API) to access the contents of the document tree for further analysis. This is redundant since the state information that is required for analysis was available at parse time. Further, DOM parsers typically limit parallel processing by building the tree before invoking analysis code. The redundancy and limits on parallel processing result in slow parsing.
Finally, data-binding parsers work by mapping XML elements to application objects (i.e., element-specific objects). However, data-binding engines often use high-cost methods such as reflection and run-time rule evaluation.
Thus, there is a need for a method and apparatus for performing XML parsing. There is a need for a method and apparatus for performing fast, XML parsing that is cost-effective and is not as labor intensive as conventional parsers.
In accordance with the teachings of the present invention, a method of generating an application-specific XML parser is presented. Compiler technology is used to automatically generate a fast and small application specific parser. An application-specific specification is provided. The application-specific specification includes two component: (1) an XML schema that specifies syntax, data elements, and data types; and (2) semantic actions: which includes a pairing of an XPath string and an action code. The application-specific specification is used to generate a state machine and state transition sequences that invoke the semantic actions. The state transition sequences are then used to generate the application-specific XML parser.
The method of the present invention includes a number of advantageous characteristics, for example, the method: (1) generates smaller code which is good for use in small device; (2) uses less memory since there is no need to parse an entire tree structure; (3) saves space since there is no need to store intermediate data structures; (4) is at least twice as fast as multithreading parsers; (5) reduces runtime analysis used to rebind data; (6) creates reusable tools based on the application specific XML schema and semantic actions; (7) results in a shorter development cycle. In one embodiment, of the inventive method may be used to quickly develop XML parsers that are smaller and faster in areas such as embedded systems, performance-critical applications, consulting services, etc. In a second embodiment, the inventive method may be incorporated as a plug-in into an integrated development environment (IDE).
A method of generating an application-specific parser, comprises the steps of: receiving a specification comprising an application specific XML schema and semantic action; generating a state machine in response to the specification; generating state transition sequences in response to the specification and the state machine; and generating an application-specific parser in response to the state transition sequences.
A computer program product comprises a computer useable medium including a computer readable program, wherein the computer readable program when executed on a computer causes the computer to: receive an application specific XML schema and semantic action specification; generate a state machine description based on the XML schema and semantic action specification; generate state transition sequences based on the XML schema and the semantic action specification; and generate an application specific parser based on the state machine description and the state transition sequences.
A method of producing a parser, comprises the steps of: accessing a specification comprising an XML schema and a semantic action with a computer; the computer automatically generating a state machine in response to accessing the specification; and the computer producing an XML parser compliant with the XML schema and the semantic actions in response to generating the state machine.
While the present invention is described herein with reference to illustrative embodiments for particular applications, it should be understood that the invention is not limited thereto. Those having ordinary skill in the art and access to the teachings provided herein will recognize additional modifications, applications, and embodiments within the scope thereof and additional fields in which the present invention would be of significant utility.
In accordance with the teachings of the present invention a method of generating an application-specific parser is presented. In one embodiment, the method is implemented as part of a software generation tool. The software generation tool produces the application-specific parser. In one embodiment, the software generation tool is implemented as part of a compiler. Using the method of the present invention, the efficiency of the SAX parser methodology is leverage, while reducing a developer's implementation burden.
A specification is provided. The specification consists of two parts. The first part is an XML schema that specifies syntax, data elements, and data types; and the second part includes semantic actions. Using the XML schema, the generation tool can determine a hierarchy of finite-state machines that can validate and parse valid sequences of XML elements at each level of the hierarchy. Second, a set of XPath expressions are paired with semantic action statements. The semantic actions are then compiled directly into appropriate callback routines (i.e., a callback routine is a routine that is executed as part of the operation of some other routine). Further, by analyzing the internal data structures, XML attributes, and XML content elements that are used within each semantic action specification, it is possible to infer data dependencies between semantic actions. From this, the generation tool can generate a relatively small set of intermediate data structures for processing an XML input document.
XPath is a language for finding information in an XML document. For example, XPath is used to navigate through elements and attributes in an XML document. An action pair is the action that is taken in conjunction with the Xpath instructions. Specifically, the semantic actions stated in 102 are launched to analyze the Xpath and action pairs as stated at 106. At step 108, the XML schema 100 and the semantic actions 102 are used to generate computer instructions that manage different states (i.e., during operation of the software generation tool a state machine is developed). An analysis is made of the XML schema 100 and the semantic actions 102 and at step 108; computer instructions (i.e., callback routines) are then generated to manage each of these different states.
Two steps are then performed as part of a validation process. At step 110 errors are generated for invalid syntactic events. At step 112, a state machine is generated for valid syntactic events. It should be appreciated that invalid syntactic events (i.e., 110) and valid syntactic events (i.e., 112) are defined based on the operation of the semantic actions 102 on the XML schema 100.
Once the state machine for valid syntactic events have been generated as shown in 112, an analysis is made to determine which combination of states in the state machine correspond to an Xpath 114. At step 116, using the syntax, data elements and data types specified at 104, the analysis of the xpath and action pairs 106 and the combination of states in the state machine that correspond to an Xpath 114, a state transition sequence is generated to invoke the actions as shown at 116. The step of generating a state transition sequence to invoke the actions 116 is then used to produce an application-specific parser 120. The application-specific parser 120 may then process XML files 118 to produce an output 122.
In one embodiment, the method of the present invention is implemented in a software generation tool. The XML schema 100 and the semantic actions 102 (i.e., the specification) serve as inputs to the application generation tool. The steps 108, 110, 112, 104, 106, 114 and 116 are the novel method steps performed by the software generation tool. The output of the software generation tool is the application-specific parser shown as 120. The application-specific parser shown by 120 then receives XML files 118 (i.e., a specific application) and then is able to efficiently parse the XML files 118 to produce an output 122. Using the software generation tool (i.e., method of the present invention), an application-specific parser 120 is automatically generated based on a specification (i.e., XML schema 100 and semantic actions 102). In one embodiment, automatically generating an application-specific parser 120 includes using the method of the present invention, to generate the computer instructions (i.e., the parser instructions) and peripheral computer instructions (i.e., events handlers, callback routines, etc) necessary to implement an application-specific parser. This alleviates the need for programmer development of computer instructions (i.e., code, software) such as event handlers and callback routines. In addition, an application specific parser is produced. The application-specific parser 120 performs quick and efficient parsing because the application-specific parser is specifically designed to parse the XML files 118 (i.e., the application).
The methods of the present invention may be implemented in software stored in one of the memories (i.e., 306, 308, 304, 320). In addition, CPU 302 may operate to perform the methods depicted in
Input device, such as tactile input device, joystick, keyboards, microphone, communications connections, or a mouse, are shown as 312. The input device 312 interfaces with the system through an input interface 314. Output devices, such as a monitor, speakers, communications connections, etc., are shown as 316. The output devices 316 communicate with computer 300 through an output interface 318.
The software generation tool implementing the teachings of the present invention may be implemented as computer instructions. The computer instructions may be stored on one of the memories (i.e., 306, 308, 304, 320). The CPU 302 may then operate under the direction of the compute instructions to implement the method of the present invention.
While the present invention is described herein with reference to illustrative embodiments for particular applications, it should be understood that the invention is not limited thereto. Those having ordinary skill in the art and access to the teachings provided herein will recognize additional modifications, applications, and embodiments within the scope thereof and additional fields in which the present invention would be of significant utility.
It is, therefore, intended by the appended claims to cover any and all such applications, modifications, and embodiments within the scope of the present invention.
This application is related to U.S. application Ser. No. ______ filed ______ and entitled, “XML COMPILER THAT GENERATES AN APPLICATION SPECIFIC XML PARSER AT RUNTIME AND CONSUMES MULTIPLE SCHEMAS” which is hereby incorporated by reference in its entirety.