CN115146111A - Method and device for querying XML configuration file content by using SQL - Google Patents

Method and device for querying XML configuration file content by using SQL Download PDF

Info

Publication number
CN115146111A
CN115146111A CN202210918419.XA CN202210918419A CN115146111A CN 115146111 A CN115146111 A CN 115146111A CN 202210918419 A CN202210918419 A CN 202210918419A CN 115146111 A CN115146111 A CN 115146111A
Authority
CN
China
Prior art keywords
xml
content
sql
configuration file
querying
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210918419.XA
Other languages
Chinese (zh)
Inventor
朱国峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Lanyun Technologies Co ltd
Original Assignee
Beijing Lanyun Technologies Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Lanyun Technologies Co ltd filed Critical Beijing Lanyun Technologies Co ltd
Priority to CN202210918419.XA priority Critical patent/CN115146111A/en
Publication of CN115146111A publication Critical patent/CN115146111A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/80Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
    • G06F16/83Querying
    • G06F16/832Query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages

Abstract

A method and apparatus for querying XML configuration file content using SQL, the method includes: acquiring XML elements in an XML configuration file; establishing a virtual configuration table according to XML elements according to a predefined rule; and querying in the virtual configuration table by using an SQL statement.

Description

Method and device for querying XML configuration file content by using SQL
Technical Field
The present application relates to the field of computers, and more particularly, to a method and apparatus for querying XML configuration file content using SQL.
Background
The configuration of the application may be loaded from a variety of carriers and data formats. The configuration data carrier may be a database, a file, etc., and the general data format includes XML, JSON, INI, TEXT, etc. The configuration carrier based on the database can directly use the SQL query capability of the database to realize the retrieval of general configuration parameters; for a configuration carrier other than a database, an application program needs to define a retrieval mode of configuration data by itself. The self-defined configuration data retrieval approach of applications is limited by implementation complexity, limited retrieval capabilities (weak compared to SQL syntax), and unclear fusion approaches of multiple XML configuration file content.
Disclosure of Invention
The application provides a method and a device for querying XML configuration file content by using SQL, which can realize the retrieval of the XML configuration file content based on the general SQL query expression syntax.
The application provides a method for querying XML configuration file content by using SQL, which comprises the following steps:
acquiring XML elements in an XML configuration file;
establishing a virtual configuration table according to XML elements according to a predefined rule;
and querying the virtual configuration table by using SQL sentences.
In an exemplary embodiment, the configuration file includes a plurality of XML elements, wherein each XML element includes a name and an attribute.
In an exemplary embodiment, the creating the virtual configuration table according to the XML element according to the predefined rule includes:
respectively establishing a virtual configuration table for each XML element;
and taking the name of the XML element as the name of the corresponding virtual configuration table.
In one exemplary embodiment, the attribute includes an attribute identification and an attribute value;
the establishing of a virtual configuration table for each XML element respectively comprises:
and taking the attribute identifier of each XML element as the column name of the virtual configuration table, and taking the attribute value of each XML element as the content in the corresponding column.
In an exemplary embodiment, at least some of the XML elements in the configuration file include content;
the virtual configuration table also comprises a content column, and each line in the content column is the content in the XML element corresponding to the virtual configuration table.
The present application further provides an apparatus for querying XML configuration file content using SQL, comprising: a memory and a processor;
the memory is used for storing a program for querying the content of the XML configuration file by using SQL;
the processor is used for reading and executing the program for querying the XML configuration file content by using SQL and executing the following operations:
acquiring XML elements in an XML configuration file;
establishing a virtual configuration table according to XML elements according to a predefined rule;
and querying the virtual configuration table by using SQL sentences.
In an exemplary embodiment, the configuration file includes a plurality of XML elements, wherein each XML element includes a name and an attribute.
In an exemplary embodiment, the creating the virtual configuration table according to the XML element according to the predefined rule includes:
respectively establishing a virtual configuration table for each XML element;
and taking the name of the XML element as the name of the corresponding virtual configuration table.
In an exemplary embodiment, the attribute includes an attribute identification and an attribute value;
the establishing of a virtual configuration table for each XML element respectively comprises:
and taking the attribute identifier of each XML element as the column name of the virtual configuration table, and taking the attribute value of each XML element as the content in the corresponding column.
In an exemplary embodiment, at least some of the XML elements in the configuration file include content;
the virtual configuration table further includes a content column, and each line in the content column is the content in the XML element corresponding to the virtual configuration table.
Compared with the related art, the application provides a method and a device for querying XML configuration file content by using SQL, and the method comprises the following steps: acquiring XML elements in an XML configuration file; establishing a virtual configuration table according to XML elements according to a predefined rule; and querying the virtual configuration table by using SQL. The method and the device can realize the retrieval of the XML configuration file content based on the general SQL query expression syntax.
Additional features and advantages of the application 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 application. Other advantages of the present application may be realized and attained by the instrumentalities and combinations particularly pointed out in the specification and the drawings.
Drawings
The accompanying drawings are included to provide an understanding of the present disclosure and are incorporated in and constitute a part of this specification, illustrate embodiments of the disclosure and together with the examples serve to explain the principles of the disclosure and not to limit the disclosure.
FIG. 1 is a flowchart of a method for querying the contents of an XML configuration file using SQL in an embodiment of the present application;
FIG. 2 is a flowchart of a method of querying the contents of an XML configuration file using SQL in accordance with an exemplary embodiment;
fig. 3 is a schematic diagram of an apparatus for querying XML configuration file content using SQL according to an embodiment of the present application.
Detailed Description
The description herein describes embodiments, but is intended to be exemplary, rather than limiting and it will be apparent to those of ordinary skill in the art that many more embodiments and implementations are possible that are within the scope of the embodiments described herein. Although many possible combinations of features are shown in the drawings and discussed in the detailed description, many other combinations of the disclosed features are possible. Any feature or element of any embodiment may be used in combination with, or instead of, any other feature or element in any other embodiment, unless expressly limited otherwise.
The present application includes and contemplates combinations of features and elements known to those of ordinary skill in the art. The embodiments, features and elements disclosed in this application may also be combined with any conventional features or elements to form a unique inventive concept as defined by the claims. Any feature or element of any embodiment may also be combined with features or elements from other inventive aspects to form yet another unique inventive aspect, as defined by the claims. Thus, it should be understood that any of the features shown and/or discussed in this application may be implemented individually or in any suitable combination. Accordingly, the embodiments are not limited except as by the appended claims and their equivalents. Further, various modifications and changes may be made within the scope of the appended claims.
Further, in describing representative embodiments, the specification may have presented the method and/or process as a particular sequence of steps. However, to the extent that the method or process does not rely on the particular order of steps set forth herein, the method or process should not be limited to the particular sequence of steps described. Other orders of steps are possible as will be understood by those of ordinary skill in the art. Therefore, the particular order of the steps set forth in the specification should not be construed as limitations on the claims. Furthermore, the claims directed to the method and/or process should not be limited to the performance of their steps in the order written, and one skilled in the art can readily appreciate that the sequences may be varied and still remain within the spirit and scope of the embodiments of the present application.
The disclosed embodiment provides a method for querying XML configuration file content using SQL, as shown in fig. 1, the method includes steps S100-S120,
s100, acquiring XML elements in an XML configuration file;
s110, establishing a virtual configuration table according to XML elements according to a predefined rule;
and S120, querying in the virtual configuration table by using SQL statements.
In this embodiment, SQL may be a syntax that conforms to the standard SQL specification, or a syntax that is custom extended SQL. In this embodiment, when the program runs, the SQL statement may be dynamically generated, or the SQL statement to be executed may be selected and set in advance, which is not specifically limited. A plurality of XML configuration files are obtained, wherein the plurality of XML configuration files can be XML configuration files which are saved in a scattered mode.
In an exemplary embodiment, each configuration file includes a plurality of XML elements, wherein each XML element includes a name and an attribute. Such as: a configuration file comprises a plurality of XML elements (elements), including the same and different elements (elements), the same XML elements (elements) having the same attribute.
In an exemplary embodiment, creating a virtual configuration table from XML elements according to predefined rules includes: respectively establishing a virtual configuration table for each XML element; and taking the name of the XML element as the name of the corresponding virtual configuration table. Such as: the name of the virtual configuration table established by the elem1 element is elem1, and the name of the virtual configuration table established by the elem2 element is elem2.
In an exemplary embodiment, the data of the XML element includes a name, an attribute, and content (content), and the attribute includes a specific attribute Identification (ID) and a plurality of general attributes (title). The value of the attribute Identification (ID) is the unique access identification of this XML element.
The establishing of a virtual configuration table for each XML element respectively comprises:
and taking the attribute identifier of each XML element as the column name of the virtual configuration table, and taking the attribute value of each XML element as the content in the corresponding column.
In an exemplary embodiment, at least some of the XML elements in the configuration file include content;
the virtual configuration table further includes a content column, and each line in the content column is corresponding to the content in the XML element corresponding to the virtual configuration table.
In the present embodiment, the attribute name and the content of each XML element are taken as the column name of the virtual table, and the attribute value and the content (content) of each XML element are taken as the content in the corresponding column. Such as: the attribute value corresponding to the identification attribute id in the elem1 element is id1-1, and the attribute value corresponding to the identification attribute id in the elem1 element is id1-2; thus, id and content are column names of the virtual configuration table, id1-1 and id1-2 are used as the content in the id column, and Element1-1 and Element1-2-2 are the content in the content column.
The embodiment provides a method for retrieving the contents of an XML configuration file by using an SQL expression syntax, which can realize the fusion and flexible query of the contents of a plurality of XML configuration files. The method is suitable for customizing projects of complex configuration files of enterprise software, and realizes automatic fusion and replacement of project customization configuration data to standard product configuration data.
Example one
According to the predefined rule, establishing a virtual configuration table according to the XML element, wherein the process comprises the following steps:
the first step, defining a virtual configuration table for each XML element, and using the name of the XML element as the name of the corresponding virtual configuration table.
And secondly, taking all attribute names and contents of each XML element as column names of the virtual table, and taking attribute values and contents (contents) of each XML element as contents in corresponding columns. Such as: the attribute value corresponding to the identification attribute id in the elem1 element is id1-1, and the attribute value corresponding to the identification attribute id in the elem1 element is id1-2; thus, id and content are column names of the virtual configuration table, id1-1 and id1-2 are contents in the id column, and Element1-1 and Element1-2-2 are contents in the content column.
For example: defining a column of the virtual table according to the attribute (attribute) of the XML element, and reserving the column as follows: ID, content (XML content is mapped to column content), and the column ID is a unique ID for identifying a single piece of data.
In the third step, the content of each XML element is a line of data of the virtual table. If the two pieces of data have the same id, the post-loaded XML element will overwrite the existing data. That is, each line corresponds to the attribute value (content) corresponding to an attribute Identification (ID) in the XML element.
With the above example method, a virtual configuration table is built for two XML configuration files:
(1) The two XML configuration file raw formats are as follows:
Figure BDA0003776604840000061
Figure BDA0003776604840000071
(2) According to the above example, two virtual configuration tables are established, as defined below:
virtual configuration table elem1 data:
id title content
id1-1 title1 Element1-1
id1-2 title1-2-2 Element1-2-2
virtual configuration table elem2 data:
id name content
id2-1 name
Id2-2 name-2
in this embodiment, elements (elements) included in an XML file are mapped to a virtual configuration table, and attributes (attributes) of the XML elements are mapped to columns of a virtual database table. The fusion and replacement of the contents of a plurality of XML files are realized through simple rules.
Example two
The method for querying the content of the XML configuration file by using SQL, as shown in FIG. 2, includes:
step 1, obtaining an XML configuration file 1 and an XML configuration file 2;
step 2, establishing a virtual configuration table according to the XML elements in the XML configuration file 1 and the XML configuration file 2 according to a predefined rule;
step 3, during operation, using SQL expression to inquire and filter configuration data;
in this step, the configuration data can be queried using SQL syntax, and the configuration data is automatically generated from multiple XML configuration files by fusion; if the data is stored in the memory database, the configuration data can be inquired and filtered through the embedded SQL engine; and if the data is stored in the XML configuration file, the data is queried by using the SQL syntax which is realized by the user.
The present application further provides an apparatus for querying XML configuration file content using SQL, as shown in fig. 3, the apparatus includes: a memory 310 and a processor 320; the memory is used for storing a program for querying the content of the XML configuration file by using SQL; the processor is used for reading and executing the program for querying the XML configuration file content by using SQL and executing the following operations:
acquiring XML elements in an XML configuration file;
establishing a virtual configuration table according to XML elements according to a predefined rule;
and querying the virtual configuration table by using SQL sentences.
In an exemplary embodiment, the configuration file includes a plurality of XML elements, wherein each XML element includes a name and an attribute.
In an exemplary embodiment, the creating the virtual configuration table according to the XML element according to the predefined rule includes:
respectively establishing a virtual configuration table for each XML element;
and taking the name of the XML element as the name of the corresponding virtual configuration table.
In an exemplary embodiment, the attribute includes an attribute Identification (ID) and an attribute value (content);
the establishing a virtual configuration table for each XML element respectively comprises:
and taking the attribute identification of each XML element as the column name of the virtual configuration table, and taking the attribute value of each XML element as the content in the corresponding column.
In an exemplary embodiment, at least some of the XML elements in the configuration file include content;
the virtual configuration table further includes a content column, and each line in the content column is the content in the XML element corresponding to the virtual configuration table.
It will be understood by those of ordinary skill in the art that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software, firmware, hardware, or suitable combinations thereof. In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be performed by several physical components in cooperation. Some or all of the components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). The term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, as is well known to those skilled in the art. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by a computer. In addition, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as is well known to those skilled in the art.

Claims (10)

1. A method for querying XML configuration file content using SQL, the method comprising:
acquiring XML elements in an XML configuration file;
establishing a virtual configuration table according to XML elements according to a predefined rule;
and querying in the virtual configuration table by using an SQL statement.
2. The method for querying XML configuration file content using SQL according to claim 1,
the configuration file includes a plurality of XML elements, where each XML element includes a name and an attribute.
3. The method of querying the contents of an XML configuration file using SQL according to claim 2, wherein the creating a virtual configuration table according to XML elements according to predefined rules comprises:
respectively establishing a virtual configuration table for each XML element;
and taking the name of the XML element as the name of the corresponding virtual configuration table.
4. The method for querying the contents of an XML configuration file using SQL according to claim 3, wherein the attributes comprise attribute identification and attribute values;
the establishing a virtual configuration table for each XML element respectively comprises:
and taking the attribute identifier of each XML element as the column name of the virtual configuration table, and taking the attribute value of each XML element as the content in the corresponding column.
5. The method for querying XML configuration file content using SQL according to claim 4,
at least part of XML elements in the configuration file comprise content;
the virtual configuration table further includes a content column, and each line in the content column is the content in the XML element corresponding to the virtual configuration table.
6. An apparatus for querying XML configuration file content using SQL, the apparatus comprising: a memory and a processor;
the memory is used for storing a program for querying the content of the XML configuration file by using SQL;
the processor is used for reading and executing the program for querying the XML configuration file content by using SQL and executing the following operations:
acquiring XML elements in an XML configuration file;
establishing a virtual configuration table according to XML elements according to a predefined rule;
and querying the virtual configuration table by using SQL sentences.
7. The apparatus for querying XML configuration file contents using SQL according to claim 6,
the configuration file includes a plurality of XML elements, where each XML element includes a name and an attribute.
8. The apparatus for querying XML configuration file contents using SQL according to claim 7, wherein the creating a virtual configuration table according to XML elements according to predefined rules comprises:
respectively establishing a virtual configuration table for each XML element;
and taking the name of the XML element as the name of the corresponding virtual configuration table.
9. The apparatus for querying XML configuration file content using SQL in accordance with claim 8, wherein the attributes comprise attribute identifications and attribute values;
the establishing a virtual configuration table for each XML element respectively comprises:
and taking the attribute identification of each XML element as the column name of the virtual configuration table, and taking the attribute value of each XML element as the content in the corresponding column.
10. The apparatus for querying XML configuration file contents using SQL according to claim 6,
at least part of XML elements in the configuration file comprise content;
the virtual configuration table further includes a content column, and each line in the content column is the content in the XML element corresponding to the virtual configuration table.
CN202210918419.XA 2022-08-01 2022-08-01 Method and device for querying XML configuration file content by using SQL Pending CN115146111A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210918419.XA CN115146111A (en) 2022-08-01 2022-08-01 Method and device for querying XML configuration file content by using SQL

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210918419.XA CN115146111A (en) 2022-08-01 2022-08-01 Method and device for querying XML configuration file content by using SQL

Publications (1)

Publication Number Publication Date
CN115146111A true CN115146111A (en) 2022-10-04

Family

ID=83413987

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210918419.XA Pending CN115146111A (en) 2022-08-01 2022-08-01 Method and device for querying XML configuration file content by using SQL

Country Status (1)

Country Link
CN (1) CN115146111A (en)

Similar Documents

Publication Publication Date Title
CN102609483B (en) General Excel import method based on configuration
CN109660372B (en) SDN service configuration method and device
CN111124474A (en) API version control method and device
CN110175157A (en) A kind of querying method and inquiry unit of column storage file
CN110569224A (en) Data deduplication method and device
CN111984666B (en) Database access method, apparatus, computer readable storage medium and computer device
CN113190325A (en) Container creation method and device
US10185757B2 (en) Non-uniform multi-row text file loading
CN116303625B (en) Data query method and device, storage medium and electronic equipment
CN109388644B (en) Data updating method and device
CN115146111A (en) Method and device for querying XML configuration file content by using SQL
CN112948503A (en) Target characteristic tree structure graph rendering method and device
CN111737369A (en) Relationship map updating method and device and storage medium
US20030084028A1 (en) Method for storing records in database or reading the same therefrom
CN107463618B (en) Index creating method and device
CN108241622B (en) Query script generation method and device
CN111290999B (en) Library file self-adaptive matching method, device and computer readable storage medium
CN109299125B (en) Database updating method and device
CN114138745A (en) Data integration method and device, storage medium and processor
CN110175303A (en) A method of according to OID code, downloading updates talking pen resource automatically
CN110489125B (en) File management method and computer storage medium
CN116756093B (en) Large object storage and query method, device, equipment and medium
CN109491966A (en) A kind of file search method and relevant apparatus
CN115168397A (en) Clickhouse database virtual column query method and device
CN111177408A (en) Method and device for realizing data processing, computer storage medium and terminal

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination