XML document analysis method and device, equipment and storage medium
Parsing XML documents through line-by-line scanning and event-driven methods solves the inefficiency problem caused by the traditional method of loading all XML documents into memory, and achieves efficient and flexible XML document parsing.
Patent Information
- Application Number
- CN202411436207.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2044-10-15
AI Technical Summary
Traditional XML document parsing methods require the entire XML document to be loaded into memory, resulting in inefficient parsing, especially when dealing with large XML documents, performance problems are serious.
The XML document is scanned line by line through the parsing processor, and the event processor is used to process target elements and document events, and element messages are generated and sent to the storage processor for persistence processing to avoid loading the entire XML document into memory.
It achieves efficient XML document parsing, takes up less memory resources, and has fast parsing speed. It can stop parsing documents at any time, and is suitable for processing large XML documents.
Smart Images

Figure CN119322868A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of XML parsing, and in particular to an XML document parsing method, device, equipment and storage medium. Background Art
[0002] In the message transmission scenario, messages are often transmitted through files in a standard protocol. When the message file is too large, the parsing efficiency and storage performance of the message file face challenges.
[0003] When messages are transmitted in XML documents, the main parsing methods for XML documents include: DOM and SAX. DOM (Document Object Model) provides a standard parsing method, but its parsing efficiency has always been unsatisfactory. This is because when DOM parses XML documents, all content is loaded into memory at once and a tree structure residing in memory is constructed. If the XML document to be parsed is too large, it will cause performance problems. Summary of the invention
[0004] The present invention provides an XML document parsing method, device, equipment and storage medium to solve the problem that the traditional XML document parsing method needs to load all contents into the memory at one time, resulting in low parsing efficiency.
[0005] In a first aspect, an embodiment of the present invention provides an XML document parsing method, comprising:
[0006] Scan the XML document line by line through the parsing processor;
[0007] When a trigger point of a target element event contained in the XML document is scanned, the trigger event processor processes the target element event and generates an element message, and sends the element message to the storage processor, so that the storage processor performs persistent processing on the target element event based on the element message;
[0008] When the trigger point of the target document event contained in the XML document is scanned, the event processor is triggered to send the target document event to the storage processor, so that the storage processor performs persistent processing on the target document event.
[0009] In a second aspect, an embodiment of the present invention provides an XML document parsing device, comprising:
[0010] A scanning module is used to scan XML documents line by line through a parsing processor;
[0011] An element processing module is used to trigger an event processor to process the target element event and generate an element message when a trigger point of a target element event contained in the XML document is scanned, and send the element message to a storage processor so that the storage processor performs persistent processing on the target element event based on the element message; the element message is used to represent a complete element and the relationship between elements;
[0012] The document processing module is used to trigger the event processor to send the target document event to the storage processor when the trigger point of the target document event contained in the XML document is scanned, so that the storage processor performs persistent processing on the target document event.
[0013] In a third aspect, an embodiment of the present invention provides an electronic device, the electronic device comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the XML document parsing method described in any embodiment of the present invention.
[0017] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the XML document parsing method described in any embodiment of the present invention when executed.
[0018] The technical solution of the embodiment of the present invention is to scan the XML document line by line in the form of data stream through the parsing processor; when the trigger point of the target element event contained in the XML document is scanned, the trigger event processor processes the target element event and generates an element message, and sends the element message to the storage processor, so that the storage processor performs persistent processing on the target element event based on the element message; when the trigger point of the target document event contained in the XML document is scanned, the trigger event processor sends the target document event to the storage processor, so that the storage processor performs persistent processing on the target document event. When parsing XML, it is not necessary to load the entire XML document into the memory, but to scan line by line and parse while scanning, which occupies less memory resources and has a fast parsing speed. The document parsing can be stopped at any time, which solves the problem that the traditional XML document parsing method needs to load all the content into the memory at one time, and the parsing efficiency is low. In addition, the event-driven form is used to respond to specific events during the parsing process, which has high flexibility and is particularly suitable for XML documents with large data volumes.
[0019] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0021] Figure 1 A flowchart of an XML document parsing method provided in Embodiment 1 of the present invention;
[0022] Figure 2 A schematic diagram of the structure of an XML document parsing device provided in Embodiment 3 of the present invention;
[0023] Figure 3 It is a structural schematic diagram of an electronic device for implementing the XML document parsing method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0025] It should be noted that the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or apparatus comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or apparatus.
[0026] Embodiment 1
[0027] Figure 1This is a flowchart of an XML document parsing method provided in the first embodiment of the present invention. This embodiment is applicable to the case of parsing and persisting XML documents. The method can be executed by an XML document parsing device. The XML document parsing device can be implemented in the form of hardware and / or software. The XML document parsing device can be configured in an electronic device. Figure 1 As shown, the method includes:
[0028] S110 , scanning the XML document line by line through a parsing processor.
[0029] The parsing processor is used to parse XML documents. XML documents can be understood as documents described in XML format; the full name of XML is Extensible Markup Language, which can also be translated as extensible markup language. XML documents can be considered to be composed of several elements, each of which is a document logic component, and an element can also contain several sub-elements.
[0030] Specifically, an XML document may include: an XML document start tag, an XML document end tag, and an element. An element may include: an element start tag, an element content, and an element end tag. The XML document is scanned line by line by a parsing processor, and the XML document is read in the form of a data stream, and parsed while being read, to prevent the memory occupation problem caused by an overly large XML document.
[0031] S120. When the trigger point of the target element event contained in the XML document is scanned, the trigger event processor processes the target element event and generates an element message, and sends the element message to the storage processor so that the storage processor performs persistent processing on the target element event based on the element message; the element message is used to represent the complete element and the relationship between elements.
[0032] Among them, the target element event can be understood as an event representing an element in an XML document. The trigger point of the target element event can be a tag that marks the element. Optionally, the target element event includes: element start event, element content event and element end event. The trigger point of the element start event is the element start tag, the trigger point of the element content event is the element text; the trigger point of the element end event is the element end tag. The element start tag and the element end tag match, and the end tag starts with a slash ( / ), such as the element start tag <msghdr> and the element end tag< / msghdr> Element text can be considered as the element content contained between the element start tag and the element end tag.
[0033] The storage processor can be understood as a processor for persisting XML documents. Optionally, the persistence processing method can be to store the XML document in a relational database in a structured manner, or to assemble the XML document into other serializable forms. A complete element can be understood as the complete data of an element; the positional relationship between elements can be understood as the relationship between an element and its sub-elements.
[0034] Specifically, when the parsing processor scans XML line by line, if it scans the trigger point of the target element event, it triggers the event processor, which processes the target element event and generates element messages representing the complete element and the relationship between elements during the processing. The element messages are sent to the storage processor so that the storage processor performs persistence processing on the target element event based on the received element messages.
[0035] This embodiment performs persistence processing on XML document elements according to the relationship between the elements, so that the document after persistence can still retain the relationship between the elements.
[0036] S130. When a trigger point of a target document event contained in the XML document is scanned, the trigger event processor sends the target document event to the storage processor, so that the storage processor performs persistence processing on the target document event.
[0037] The target element event can be understood as an event indicating the start or end of an XML document. The target document events include: document start events and document end events; the trigger point of the document start event is the document start tag, and the trigger point of the document end event is the document end tag. Exemplarily, the document start tag can be a sequence code, which can include: XML document declaration and comments. The document end tag can be the end tag of the root element.
[0038] Specifically, when the parsing processor scans XML line by line, if it scans the trigger point of the target document event, it triggers the event processor, and the event processor sends the target document event to the storage processor, so that the storage processor performs persistent processing on the target document event.
[0039] The technical solution of the embodiment of the present invention is to scan the XML document line by line in the form of data stream through the parsing processor; when the trigger point of the target element event contained in the XML document is scanned, the trigger event processor processes the target element event and generates an element message, and sends the element message to the storage processor, so that the storage processor performs persistent processing on the target element event based on the element message; when the trigger point of the target document event contained in the XML document is scanned, the trigger event processor sends the target document event to the storage processor, so that the storage processor performs persistent processing on the target document event. When parsing XML, it is not necessary to load the entire XML document into the memory, but to scan it line by line and parse it while scanning, which occupies less memory resources and has a fast parsing speed, and the document parsing can be stopped at any time. And the event-driven form is used to respond to specific events during the parsing process, which is highly flexible and particularly suitable for XML documents with large data volumes.
[0040] As an optional embodiment of the present application, the event processor includes: an element stack and a level bucket; the element stack is used to record element numbers and cache element texts that are not currently fully processed; the level bucket is used to store the element numbers and levels of the elements that are not currently fully processed.
[0041] The element stack can be understood as a data stack used to record the order of elements and cache the text of the elements that are not fully processed at the moment. The level bucket can be understood as a container that stores the element number and level of the element that is not fully processed at the moment. The element number can be understood as the sequence number assigned to each element in the XML document.
[0042] As an optional embodiment of the embodiment of the present application, S120, when a trigger point of a target element event contained in the XML document is scanned, the triggering event processor processes the target element event and generates an element message, and the step of sending the element message to the storage processor includes:
[0043] S121. When the element start tag contained in the XML document is scanned, the event handler is triggered. If the element start tag is not recorded in the document structure template, the static general element is pushed into the element stack; if the element start tag is recorded in the document structure template, an element number is assigned to the element marked by the element start tag, and the element is pushed into the element stack.
[0044] The document structure template can be understood as a template for recording the elements that need attention in the document. The document structure template can be obtained by cutting the standard complete message tree structure. The label definition in XML corresponding to each node in the document structure template may include: business semantics, regular check, value conversion rules, whether it is a cyclic domain and whether it can be compressed, etc. Optionally, the document structure template records the elements that need attention in the form of a node tree, and each node corresponds to an element tag in the XML document.
[0045] Specifically, the document parser scans the XML document line by line. When the element start tag is scanned, the event processor is triggered to determine whether the element start tag is recorded in the document structure template. If the element start tag is not recorded in the document structure template, it means that the element marked by the scanned element start tag does not need to be paid attention to, and the static general element is pushed into the element stack. Although there is no need to pay attention to it, pushing the static general element into the stack can act as a placeholder to avoid confusion between the relationships between elements during the parsing process. If the element start tag is recorded in the document structure template, it means that the element marked by the scanned element start tag needs to be paid attention to, then the element number is assigned to the element marked by the element start tag, and the element is pushed into the element stack. And continue to scan the XML document line by line through the parsing processor.
[0046] It should be noted that, since there are nested elements in the XML document, several element start tags may be scanned continuously. Multiple elements may be pushed into the element stack, but they are not necessarily complete elements.
[0047] S122. When the element text contained in the XML document is scanned, the event handler is triggered. If the top element of the element stack is not recorded in the document structure template, the element text is discarded; if the top element of the element stack is recorded in the document structure template, the element text is pushed into the element stack.
[0048] Specifically, the document parser scans the XML document line by line. When the element start tag is scanned, the event processor is triggered to determine whether the top element of the element stack is recorded in the document structure template, that is, whether the element start tag is recorded in the document structure template. If the top element of the element stack is not recorded in the document structure template, it means that the element does not need to be paid attention to, and the element text can be discarded without pushing the element, or no action is performed. If the top element of the element stack is recorded in the document structure template, it means that the element needs to be paid attention to, and the element text is pushed into the element stack. And continue to scan the XML document line by line through the parsing processor.
[0049] S123. When the element end tag contained in the XML document is scanned, the event handler is triggered. If the top element of the element stack is not recorded in the document structure template, the element stack is popped. If the top element of the element stack is recorded in the document structure template, an element message is generated according to the compression state of the element, the element message is sent to the storage processor and the element stack is popped, so that the storage processor performs persistence processing on the target element event based on the element message.
[0050] Specifically, the document parser scans the XML document line by line. When the element end tag is scanned, the event processor is triggered to determine whether the top element of the element stack is recorded in the document structure template. If the top element of the element stack is not recorded in the document structure template, it means that the element does not need to be paid attention to. Since the static general element is pushed into the element stack for the element that is not paid attention to, the element stack can be unstacked. If the top element of the element stack is recorded in the document structure template, it means that the element needs to be paid attention to, and the element text has been pushed in the element stack. However, in the XML document, the element may also contain multiple layers of sub-elements, that is, the element is in a compressed state, and there will be a certain relationship between the elements. Therefore, it is necessary to generate an element message containing a complete element and a relationship between elements according to the compressed state of the element, and send the element message to the storage processor so that the storage processor performs persistent processing on the target element event based on the element message. At this point, the elements in the element stack are parsed and the element stack is unstacked.
[0051] In an optional embodiment, S123, the step of triggering the event processor to generate an element message according to the compression state of the element when the top element of the element stack is recorded in the document structure template, sending the element message to the storage processor and unstacking the element stack so that the storage processor performs persistent processing on the target element event based on the element message includes:
[0052] S1231. Trigger the event handler. When the top element of the element stack is recorded in the document structure template, if the element is compressed, place the numbers of all elements contained in the sub-levels of the current level where the element is located in the current level in the level bucket.
[0053] The document parser scans the XML document line by line. When the element end tag is scanned, the event processor is triggered to determine whether the element is compressed according to the tag definition corresponding to the element node in the document structure template, if the element is compressed. If the element is compressed, the numbers of all elements contained in the sub-level of the current level where the element is located are placed in the current level in the level bucket, that is, the compressed elements in the sub-level are decompressed into the current level.
[0054] S1232. If the element is not compressed or decompressed, the complete element message in the element stack is popped and sent to the storage processor; the parent-child relationship message between the element numbers contained in the current level and the child element numbers contained in the child level is sent to the storage processor, so that the storage processor persistently stores the complete element message according to the parent-child relationship message; the element number in the current level is placed in the current level in the level bucket, and the elements in the element stack are parsed, and the element stack is popped.
[0055] Specifically, if the element is not compressed or is decompressed after the operation of S1231, the complete element message in the element stack is popped and the complete element message is sent to the storage processor; according to the parent-child relationship between the elements, the parent-child relationship message between the numbers of the elements contained in the current level and the numbers of the child elements contained in the child level is determined, and the parent-child relationship message between the elements is sent to the storage processor, so that the storage processor performs persistent storage of the elements according to the received parent-child relationship message between the elements and the complete element message. The element number in the current level is placed in the current level in the level bucket, which is used to determine the parent-child relationship message between the element corresponding to the element number in the current level and its parent element. At this point, the elements in the element stack are parsed and the element stack is popped.
[0056] As an optional embodiment of the embodiment of the present application, S130, when a trigger point of a target document event contained in the XML document is scanned, triggering the event processor to send the target document event to the storage processor so that the storage processor performs persistent processing on the target document event includes:
[0057] S131. When a document start tag contained in the XML document is scanned, the event processor is triggered to send a document start event to the storage processor, so that the storage processor performs a storage initialization operation.
[0058] Specifically, when the parsing processor scans the document start tag contained in the XML document, it indicates that the document needs to be parsed, and the triggering event processor sends the document start event to the storage processor, and the storage processor performs the initialization operation of the storage file. Exemplarily, the initialization operation may include: creating a data table, a data storage path, and data access permissions, etc.
[0059] S132. When a document termination tag included in the XML document is scanned, the event processor is triggered to send a document termination event to the storage processor, so that the storage processor performs a storage closing action.
[0060] Specifically, when the parsing processor scans the document termination tag contained in the XML document, it indicates that the parsing of the document needs to be terminated, and the triggering event processor sends the document termination event to the storage processor, so that the storage processor stores the parsed file. Exemplarily, the storage termination action can be to trigger a downstream batch processing task to perform content analysis, etc.
[0061] Embodiment 2
[0062] Figure 2 This is a schematic diagram of the structure of an XML document parsing device provided by Embodiment 3 of the present invention. Figure 2 As shown, the device includes: a scanning module 210, an element processing module 220 and a document processing module 230; wherein,
[0063] The scanning module 210 is used to scan the XML document line by line through a parsing processor;
[0064] The element processing module 220 is used to trigger the event processor to process the target element event and generate an element message when the trigger point of the target element event contained in the XML document is scanned, and send the element message to the storage processor so that the storage processor performs persistent processing on the target element event based on the element message; the element message is used to represent a complete element and the relationship between elements;
[0065] The document processing module 230 is used to trigger the event processor to send the target document event to the storage processor when a trigger point of the target document event contained in the XML document is scanned, so that the storage processor performs persistent processing on the target document event.
[0066] The technical solution of the embodiment of the present invention is to scan the XML document line by line in the form of data stream through the parsing processor; when the trigger point of the target element event contained in the XML document is scanned, the trigger event processor processes the target element event and generates an element message, and sends the element message to the storage processor, so that the storage processor performs persistent processing on the target element event based on the element message; when the trigger point of the target document event contained in the XML document is scanned, the trigger event processor sends the target document event to the storage processor, so that the storage processor performs persistent processing on the target document event. When parsing XML, it is not necessary to load the entire XML document into the memory, but to scan it line by line and parse it while scanning, which occupies less memory resources and has a fast parsing speed, and the document parsing can be stopped at any time. And the event-driven form is used to respond to specific events during the parsing process, which is highly flexible and particularly suitable for XML documents with large data volumes.
[0067] Optionally, the target document event includes: a document start event and a document end event; the trigger point of the document start event is the document start tag, and the trigger point of the document end event is the document end tag;
[0068] The target element events include: element start event, element content event and element end event; the trigger point of element start event is element start tag, the trigger point of element content event is element text; the trigger point of element end event is element end tag.
[0069] Optionally, the event processor includes: an element stack and a level bucket; the element stack is used to record the order of elements and cache the element text that is not fully processed at present; the level bucket is used to store the element number and level of the element that is not fully processed at present.
[0070] Optionally, the element processing module 220 includes:
[0071] a start tag processing unit, configured to trigger the event processor when an element start tag contained in the XML document is scanned, and to push a static common element into the element stack if the element start tag is not recorded in the document structure template; and to assign an element number to an element marked by the element start tag and push the element into the element stack if the element start tag is recorded in the document structure template;
[0072] An element text processing unit, configured to trigger the event processor when an element text contained in the XML document is scanned, and to discard the element text if the top element of the element stack is not recorded in the document structure template; and to push the element text into the element stack if the top element of the element stack is recorded in the document structure template;
[0073] An end tag processing unit is used to trigger the event handler when scanning an element end tag contained in the XML document, and to pop the element stack if the top element of the element stack is not recorded in the document structure template; and to generate an element message according to the compression state of the element if the top element of the element stack is recorded in the document structure template, and to send the element message to the storage processor and pop the element stack, so that the storage processor performs persistence processing on the target element event based on the element message.
[0074] Optionally, the end tag processing unit is specifically used to:
[0075] The event handler is triggered, and when the top element of the element stack is recorded in the document structure template, if the element is compressed, the numbers of all elements contained in the sub-levels of the current level where the element is located are placed in the current level in the level bucket;
[0076] If the element is not compressed or decompressed, the element complete message in the element stack is popped and sent to the storage processor; the element parent-child relationship message between the element numbers contained in the current level and the child element numbers contained in the child level is sent to the storage processor, so that the storage processor persists the element complete message according to the element parent-child relationship message; the element number in the current level is placed in the current level in the level bucket and the element stack is popped.
[0077] Optionally, the document structure template records the elements that require attention in the form of a node tree, and each node corresponds to an element tag in the XML document.
[0078] Optionally, the document processing module 230 is specifically configured to:
[0079] When a document start tag contained in the XML document is scanned, the event processor is triggered to send a document start event to the storage processor, so that the storage processor performs a storage initialization operation;
[0080] When the document termination tag contained in the XML document is scanned, the event processor is triggered to send the document termination event to the storage processor, so that the storage processor performs a storage closing action.
[0081] The XML document parsing device provided in the embodiment of the present invention can execute the XML document parsing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0082] Embodiment 3
[0083] Figure 3 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0084] like Figure 3 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0085] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0086] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as an XML document parsing method.
[0087] In some embodiments, the XML document parsing method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the XML document parsing method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the XML document parsing method in any other appropriate manner (e.g., by means of firmware).
[0088] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0089] In some embodiments, the XML document parsing method can be implemented as a computer program, which is invisibly included in a computer program product. When the computer program is executed by a processor, the XML document parsing method of the present invention is implemented. The computer program product can be understood as a software product that mainly implements its solution through a computer program.
[0090] The computer programs implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer programs are executed by the processor, the functions / operations specified in the flow charts and / or block diagrams are implemented. The computer programs may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0091] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0092] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0093] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0094] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0095] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0096] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for parsing an XML document, characterized in that: include: Scan the XML document line by line through the parsing processor; When a trigger point of a target element event contained in the XML document is scanned, the trigger event processor processes the target element event and generates an element message, and sends the element message to the storage processor, so that the storage processor performs persistent processing on the target element event based on the element message; the element message is used to represent a complete element and the relationship between elements; When the trigger point of the target document event contained in the XML document is scanned, the event processor is triggered to send the target document event to the storage processor, so that the storage processor performs persistent processing on the target document event.
2. The XML document parsing method according to claim 1, characterized in that: The target document events include: document start events and document end events; the trigger point of the document start event is the document start tag, and the trigger point of the document end event is the document end tag; The target element events include: element start event, element content event and element end event; the trigger point of element start event is element start tag, the trigger point of element content event is element text; the trigger point of element end event is element end tag.
3. The XML document parsing method according to claim 2, characterized in that: The event processor includes: an element stack and a level bucket; the element stack is used to record the order of elements and cache the element text that is not fully processed at present; the level bucket is used to store the element number and level of the element that is not fully processed at present.
4. The XML document parsing method according to claim 3, characterized in that: When a trigger point of a target element event contained in the XML document is scanned, the trigger event processor processes the target element event and generates an element message, and the step of sending the element message to the storage processor includes: When the element start tag contained in the XML document is scanned, the event handler is triggered, and if the element start tag is not recorded in the document structure template, the static general element is pushed into the element stack; if the element start tag is recorded in the document structure template, an element number is assigned to the element marked by the element start tag, and the element is pushed into the element stack; When the element text contained in the XML document is scanned, the event handler is triggered, and if the top element of the element stack is not recorded in the document structure template, the element text is discarded; if the top element of the element stack is recorded in the document structure template, the element text is pushed into the element stack; When the element end tag contained in the XML document is scanned, the event handler is triggered, and if the top element of the element stack is not recorded in the document structure template, the element stack is popped; if the top element of the element stack is recorded in the document structure template, an element message is generated according to the compression state of the element, the element message is sent to the storage processor and the element stack is popped, so that the storage processor performs persistence processing on the target element event based on the element message.
5. The XML document parsing method according to claim 4, characterized in that: The step of triggering the event processor to generate an element message according to the compression state of the element when the top element of the element stack is recorded in the document structure template, sending the element message to the storage processor and unstacking the element stack so that the storage processor performs persistent processing on the target element event based on the element message includes: The event handler is triggered, and when the top element of the element stack is recorded in the document structure template, if the element is compressed, the numbers of all elements contained in the sub-levels of the current level where the element is located are placed in the current level in the level bucket; If the element is not compressed or decompressed, the element complete message in the element stack is popped and sent to the storage processor; the element parent-child relationship message between the element numbers contained in the current level and the child element numbers contained in the child level is sent to the storage processor, so that the storage processor persists the element complete message according to the element parent-child relationship message; the element number in the current level is placed in the current level in the level bucket and the element stack is popped.
6. The XML document parsing method according to any one of claims 4-5, characterized in that: The document structure template records the elements that require attention in the form of a node tree, and each node corresponds to an element tag in the XML document.
7. The XML document parsing method according to claim 1, characterized in that: When a trigger point of a target document event contained in the XML document is scanned, the step of triggering the event processor to send the target document event to the storage processor so that the storage processor performs persistent processing on the target document event includes: When a document start tag contained in the XML document is scanned, the event processor is triggered to send a document start event to the storage processor, so that the storage processor performs a storage initialization operation; When the document termination tag contained in the XML document is scanned, the event processor is triggered to send the document termination event to the storage processor, so that the storage processor performs a storage closing action.
8. An XML document parsing device, characterized in that: include: A scanning module is used to scan XML documents line by line through a parsing processor; An element processing module is used to trigger an event processor to process the target element event and generate an element message when a trigger point of a target element event contained in the XML document is scanned, and send the element message to a storage processor so that the storage processor performs persistent processing on the target element event based on the element message; the element message is used to represent a complete element and the relationship between elements; The document processing module is used to trigger the event processor to send the target document event to the storage processor when the trigger point of the target document event contained in the XML document is scanned, so that the storage processor performs persistent processing on the target document event.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the XML document parsing method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the XML document parsing method according to any one of claims 1 to 7 when executed.
Citation Information
Patent Citations
Measuring method of similarity between extensive makeup language (XML) file structure outlines
CN102622432A
JSAX (joint simple API (application program interface) for XML (extensible markup language)) parser and parsing method based on syntactic analysis of backtracking automaton
CN102708155A
Sliding window technology based hardware XML (Extensive Markup Language) parser
CN104267998A
XML file retrieval method and apparatus
CN105354282A
Quick query method for XML stream data
CN107256218A