An XML document parsing method, device, equipment and storage medium

CN119322868BActive Publication Date: 2026-10-27成方金融科技有限公司
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411436207.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-15
Publication Date
2026-10-27
Estimated Expiration
2044-10-15

AI Technical Summary

Technical Problem

[0004]本发明提供了一种XML文档解析方法、装置、设备及存储介质,以解决传统XML文档解析方法需要把所有内容一次性的装载入内存,解析效率低的问题

Benefits of technology

[0018]本发明实施例的技术方案,通过解析处理器按照数据流的形式对XML文档进行逐行扫描;在扫描到XML文档包含的目标元素事件的触发点时,触发事件处理器处理目标元素事件并产生元素消息,向存储处理器发送元素消息,以使存储处理器基于元素消息对目标元素事件进行持久化处理;在扫描到XML文档包含的目标文档事件的触发点时,触发事件处理器将目标文档事件发送到存储处理器,以使存储处理器对目标文档事件进行持久化处理。在解析XML时不需要将整个XML文档载入内存,而是逐行扫描并且一边扫描一边解析,占用的内存资源少且解析速度快,可以在任何时候停止解析文档,解决了传统XML文档解析方法需要把所有内容一次性的装载入内存,解析效率低的问题。并且利用事件驱动的形式在解析过程中对特定事件做出响应,灵活性高,尤其适用于数据量大的XML文档。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119322868B_ABST
    Figure CN119322868B_ABST
Patent Text Reader

Abstract

The application discloses an XML document parsing method, device and equipment and a storage medium. The method comprises the following steps: an analysis processor performs line-by-line scanning on an XML document in the form of a data stream; when a trigger point of a target element event contained in the XML document is scanned, an event processor is triggered to process the target element event and generate an element message, and the element message is sent to a storage processor, so that the storage processor performs persistent processing on the target element event based on the element message; when a trigger point of a target document event contained in the XML document is scanned, 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. When the XML is parsed, the entire XML document does not need to be loaded into the memory, but is scanned line by line and parsed simultaneously, so that the occupied memory resource is small and the parsing speed is fast.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of XML parsing technology, and in particular to an XML document parsing method, apparatus, device, and storage medium. Background Technology

[0002] In message transmission scenarios, messages are often transmitted via files according to a certain standard protocol. When the message file becomes too large, the parsing efficiency and storage performance of the message file face challenges.

[0003] When messages are transmitted as XML documents, the main methods for parsing XML documents include DOM and SAX. DOM (Document Object Model) provides the standard parsing method, but its parsing efficiency has always been unsatisfactory. This is because when parseting an XML document, DOM loads all the content into memory at once and builds a tree structure residing in memory. If the XML document to be parsed is too large, it will cause performance issues. Summary of the Invention

[0004] This invention provides an XML document parsing method, apparatus, device, and storage medium to solve the problem of low parsing efficiency caused by traditional XML document parsing methods requiring all content to be loaded into memory at once.

[0005] In a first aspect, embodiments of the present invention provide an XML document parsing method, including:

[0006] The XML document is scanned line by line by the parser.

[0007] When the trigger point of the target element event contained in the XML document is detected, the trigger event handler processes the target element event and generates an element message, and sends the element message to the storage processor so that the storage processor can persist the target element event based on the element message;

[0008] When the event handler detects a trigger point for a target document event contained in the XML document, it sends the target document event to the storage processor so that the storage processor can persist the target document event.

[0009] Secondly, embodiments of the present invention provide an XML document parsing apparatus, comprising:

[0010] The scanning module is used to scan the XML document line by line using the parsing processor;

[0011] The element processing module 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 detected, and to send the element message to the storage processor so that the storage processor can perform 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;

[0012] The document processing module is configured to, when scanning a trigger point for a target document event contained in the XML document, trigger the event handler to send the target document event to the storage processor, so that the storage processor can persist the target document event.

[0013] Thirdly, embodiments of the present invention provide 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 that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the XML document parsing method according to any embodiment of the present invention.

[0017] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer instructions, which are used to cause a processor to execute the XML document parsing method described in any embodiment of the present invention.

[0018] The technical solution of this invention involves a parsing processor scanning an XML document line by line in a data stream format. When a trigger point for a target element event within the XML document is encountered, an event processor is triggered to process the target element event and generate an element message, which is then sent to a storage processor. This allows the storage processor to persist the target element event based on the element message. Similarly, when a trigger point for a target document event is encountered, the event processor sends the target document event to the storage processor, enabling the storage processor to persist the target document event. This method avoids loading the entire XML document into memory during parsing; instead, it scans line by line and parses simultaneously, resulting in lower memory usage and faster parsing speed. Parsing can be stopped at any time, solving the problem of low efficiency caused by loading all content into memory at once in traditional XML parsing methods. Furthermore, the event-driven approach allows for responses to specific events during parsing, offering high flexibility and making it particularly suitable for large-volume XML documents.

[0019] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0020] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 This is a flowchart of an XML document parsing method provided in Embodiment 1 of the present invention;

[0022] Figure 2 This is a schematic diagram of the structure of an XML document parsing device provided in Embodiment 3 of the present invention;

[0023] Figure 3 This is a schematic diagram of the structure of an electronic device that implements the XML document parsing method of this invention. Detailed Implementation

[0024] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0025] It should be noted that the terms "comprising" and "having" and any variations thereof in the specification, claims and accompanying drawings of this invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such process, method, product or device.

[0026] Example 1

[0027] Figure 1This is a flowchart of an XML document parsing method provided in Embodiment 1 of the present invention. This embodiment is applicable to the parsing and persistence of XML documents. The method can be executed by an XML document parsing device, which can be implemented in hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes:

[0028] S110. The XML document is scanned line by line by the parser.

[0029] The parser processor is used to parse and process XML documents. An XML document can be understood as a document described in XML format; XML stands for Extensible Markup Language. An XML document can be considered as composed of several elements, each of which is a logical component of the document, and an element can also contain several child elements.

[0030] Specifically, an XML document can include: an XML document start tag, an XML document end tag, and elements. Elements can include: an element start tag, element content, and element end tag. The parser scans the XML document line by line, reading it as a data stream, parsing as it reads, thus preventing memory consumption issues caused by excessively large XML documents.

[0031] S120. When the trigger point of the target element event contained in the XML document is detected, the event handler is triggered to process the target element event and generate an element message, and send the element message to the storage processor so that the storage processor can persist 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] In this context, target element events can be understood as events occurring on elements within an XML document. The trigger point for a target element event can be the tag of the element. Optionally, target element events include: element start events, element content events, and element end events. The trigger point for an element start event is the element's start tag; the trigger point for an element content event is the element's text; and the trigger point for an element end event is the element's end tag. The element start tag and element end tag must match, and the end tag must begin with a forward slash ( / ), such as the element start tag... <msghdr> and element closing tag< / msghdr> Element text can be considered as the content contained between the element's start tag and end tag.

[0033] A storage processor can be understood as a processor used to persist XML documents. Optionally, persistence can involve storing the XML document in a structured manner within a relational database, or assembling the XML document into other serializable formats. 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 child elements.

[0034] Specifically, when the parser scans the XML line by line, if it finds a trigger point for a target element event, it triggers the event handler, which processes the target element event and generates an element message representing the complete element and the relationship between elements during the processing. The element message is then sent to the storage handler so that the storage handler can persist the target element event based on the received element message.

[0035] This embodiment performs persistence processing on XML document elements based on the relationships between elements, so that the persisted document can still retain the relationships between elements.

[0036] S130. When the trigger point of the target document event contained in the XML document is detected, the trigger event handler sends the target document event to the storage processor so that the storage processor can persist the target document event.

[0037] In this context, target element events can be understood as events that indicate the beginning or end of an XML document. Target document events include: document start events and document end events; the document start event is triggered by the document start tag, and the document end event is triggered by the document end tag. For example, the document start tag can be a sequence number, which can include XML document declarations and comments. The document end tag can be the end tag of the root element.

[0038] Specifically, when the parser scans the XML line by line, if it finds a trigger point for a target document event, it triggers the event handler, which then sends the target document event to the storage handler so that the storage handler can persist the target document event.

[0039] The technical solution of this invention involves a parsing processor scanning an XML document line by line in a data stream format. When a trigger point for a target element event within the XML document is encountered, an event processor is triggered to process the target element event and generate an element message, which is then sent to a storage processor. This allows the storage processor to persist the target element event based on the element message. Similarly, when a trigger point for a target document event is encountered, the event processor sends the target document event to the storage processor, enabling the storage processor to persist the target document event. This approach eliminates the need to load the entire XML document into memory during parsing; instead, it scans line by line and parses simultaneously, resulting in lower memory usage and faster parsing speeds. Parsing can be stopped at any time. Furthermore, the event-driven approach allows for responses to specific events during parsing, offering high flexibility and making it particularly suitable for large-volume XML documents.

[0040] As an optional embodiment of this application, the event handler includes: an element stack and a hierarchy bucket; the element stack is used to record element numbers and cache the text of elements that are not currently fully processed; the hierarchy bucket is used to store the element number and hierarchy 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 elements that have not yet been fully processed. The hierarchy bucket can be understood as a container that stores the element number and hierarchy of the element that has not yet been fully processed. The element number can be understood as the sequence number assigned to each element in the XML document.

[0042] As an optional embodiment of this application, S120, when the trigger point of the target element event contained in the XML document is detected, the step of triggering the event handler to process the target element event and generate an element message, and sending the element message to the storage processor includes:

[0043] S121. When the start tag of an element contained in the XML document is detected, the event handler is triggered. If the start tag of the element is not recorded in the document structure template, the static general element is pushed onto the element stack. If the start tag of the element is recorded in the document structure template, an element number is assigned to the element marked by the start tag, and the element is pushed onto the element stack.

[0044] The document structure template can be understood as a template that records the elements of interest in a document. It can be obtained by trimming a standard complete message tree structure. Each node in the document structure template corresponds to a tag definition in the XML, which may include: business semantics, regular expression validation, value conversion rules, whether it is a circular field, and whether it can be compressed, etc. Optionally, the document structure template records the elements of interest in the form of a node tree, with each node corresponding to an element tag in the XML document.

[0045] Specifically, the document parser scans the XML document line by line. When it encounters an element's start tag, it triggers an event handler to determine if the start tag is recorded in the document structure template. If the start tag is not recorded, it means the element marked by the scanned start tag is not of interest, and a static generic element is pushed onto the element stack. Although not of interest, pushing a static generic element onto the stack acts as a placeholder, preventing confusion between elements during parsing. If the start tag is recorded in the document structure template, it means the element marked by the scanned start tag is of interest, and an element number is assigned to the element marked by the start tag, which is then pushed onto the element stack. The parser then continues scanning the XML document line by line.

[0046] It should be noted that due to nesting of elements in an XML document, several element start tags can be scanned consecutively. Multiple elements can be pushed onto the element stack, but these 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 onto the element stack.

[0048] Specifically, the document parser scans the XML document line by line. When it encounters an element's start tag, it triggers an event handler to determine if the top element of the element stack is recorded in the document structure template, i.e., whether the element's 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 is not important and can be discarded without pushing the element onto the stack, or no action is taken. If the top element of the element stack is recorded in the document structure template, it means that the element is important and the element's text is pushed onto the element stack. The parser then continues to scan the XML document line by line.

[0049] S123. When the closing tag of an element contained in the XML document is detected, 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 can persist the target element event based on the element message.

[0050] Specifically, the document parser scans the XML document line by line. When it encounters an element's closing tag, it triggers an event handler to check if the top element of the element stack is recorded in the document structure template. If the top element is not recorded, it means the element doesn't need attention. Since uninterested elements are pushed onto the element stack as static, generic elements, a pop operation can be performed on the stack. If the top element is recorded in the document structure template, it means the element needs attention, and its text has already been pushed onto the stack. However, elements in an XML document may contain multiple levels of child elements, meaning the elements are compressed and relationships exist between them. Therefore, an element message containing the complete element and its relationships needs to be generated based on the compression state and sent to the storage processor. This allows the storage processor to persist the target element's events based on the element message. At this point, the parsing of the elements in the element stack is complete, and the element stack is popped.

[0051] In an optional embodiment, S123, the step of triggering the event processor to generate an element message based on 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 popping the element stack so that the storage processor can persist the target element event based on the element message includes:

[0052] S1231. Trigger the event handler. If the top element of the element stack is recorded in the document structure template and the element is compressed, place the numbers of all elements contained in the sub-levels of the current level where the element is located into the current level of the level bucket.

[0053] The document parser scans the XML document line by line. When it encounters an element's closing tag, it triggers an event handler to determine if the top element of the element stack is recorded in the document structure template. Based on the tag definition corresponding to the element node in the document structure template, it determines whether the element is compressed. If the element is compressed, it places the numbers of all elements contained in the child levels of the current level within the current level's bucket; in other words, it decompresses the compressed elements in the child levels into the current level.

[0054] S1232. If the element is not compressed or decompressed, the complete element message in the element stack is popped from the stack and sent to the storage processor; the parent-child relationship message between the element number of the current level and the child element number of the child level is sent to the storage processor so that the storage processor can persistently store the complete element message according to the parent-child relationship message; the element number in the current level is placed into the current level in the level bucket, thus completing the parsing of the elements in the element stack and performing a pop operation on the element stack.

[0055] Specifically, if an element is not compressed or is decompressed after operation S1231, the complete element message is popped from the element stack and sent to the storage processor. Based on the parent-child relationships between elements, the parent-child relationship message between the element number in the current level and the child element numbers in the child level is determined and sent to the storage processor. This allows the storage processor to persistently store the element based on the received parent-child relationship message and the complete element message. The element number in the current level is placed into the current level bucket to determine the parent-child relationship message between the element corresponding to the current level and its parent element. At this point, the parsing of the elements in the element stack is complete, and the element stack is popped.

[0056] As an optional embodiment of this application, S130, the step of triggering the event handler 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 detected, so that the storage processor performs persistence processing on the target document event, includes:

[0057] S131. When the document start tag contained in the XML document is scanned, the event handler is triggered to send the document start event to the storage processor so that the storage processor performs a storage initialization operation.

[0058] Specifically, when the parsing processor detects a document start tag in an XML document, it indicates that the document needs to be parsed. This triggers an event processor to send a document start event to the storage processor, which then performs initialization operations on the stored file. For example, initialization operations may include creating data tables, data storage paths, and data access permissions.

[0059] S132. When a document termination tag is detected in the XML document, the event handler is triggered to send a document termination event to the storage processor, so that the storage processor performs a storage cleanup action.

[0060] Specifically, when the parsing processor encounters a document termination tag in an XML document, it indicates that parsing of the document needs to end. This triggers an event handler to send a document termination event to the storage processor, causing the storage processor to store the parsed file. For example, the storage termination action could trigger downstream batch processing tasks to perform content analysis, etc.

[0061] Example 2

[0062] Figure 2 This is a schematic diagram of the structure of an XML document parsing device provided in 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] Scanning module 210 is used to scan an XML document line by line using a parsing processor;

[0064] The element processing module 220 is configured to, when scanning the trigger point of a target element event contained in the XML document, trigger the event processor to process the target element event and generate an element message, and send the element message to the storage processor so that the storage processor can perform 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;

[0065] The document processing module 230 is configured to, when scanning a trigger point for a target document event contained in the XML document, trigger the event processor to send the target document event to the storage processor, so that the storage processor can perform persistent processing on the target document event.

[0066] The technical solution of this invention involves a parsing processor scanning an XML document line by line in a data stream format. When a trigger point for a target element event within the XML document is encountered, an event processor is triggered to process the target element event and generate an element message, which is then sent to a storage processor. This allows the storage processor to persist the target element event based on the element message. Similarly, when a trigger point for a target document event is encountered, the event processor sends the target document event to the storage processor, enabling the storage processor to persist the target document event. This approach eliminates the need to load the entire XML document into memory during parsing; instead, it scans line by line and parses simultaneously, resulting in lower memory usage and faster parsing speeds. Parsing can be stopped at any time. Furthermore, the event-driven approach allows for responses to specific events during parsing, offering high flexibility and making it particularly suitable for large-volume XML documents.

[0067] Optionally, the target document events include: a document start event and a document end event; the trigger point for the document start event is the document start tag, and the trigger point for 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 element start event is triggered by the element start tag, the element content event is triggered by the element text, and the element end event is triggered by the element end tag.

[0069] Optionally, the event handler includes: an element stack and a hierarchy bucket; the element stack is used to record the order of elements and cache the text of elements that have not been fully processed; the hierarchy bucket is used to store the element number and hierarchy of the elements that have not been fully processed.

[0070] Optionally, the element processing module 220 includes:

[0071] The start tag processing unit is configured to trigger the event handler when the start tag of an element contained in the XML document is detected, and push the static general element onto the element stack if the start tag is not recorded in the document structure template; and assign an element number to the element marked by the start tag and push the element onto the element stack if the start tag is recorded in the document structure template.

[0072] The element text processing unit is used to trigger the event handler when the element text contained in the XML document is scanned, and discard the element text if the top element of the element stack is not recorded in the document structure template; and push the element text onto the element stack if the top element of the element stack is recorded in the document structure template.

[0073] The closing tag processing unit is configured to trigger the event handler when an element closing tag is detected in the XML document, and pop the element stack if the top element of the element stack is not recorded in the document structure template; if the top element of the element stack is recorded in the document structure template, generate an element message according to the compression state of the element, send the element message to the storage processor, and pop the element stack, so that the storage processor can persist the target element event based on the element message.

[0074] Optionally, the end tag processing unit is specifically used for:

[0075] If the element at the top of the element stack is recorded in the document structure template, and the element is compressed, then 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 of the hierarchical bucket.

[0076] If the element is not compressed or decompressed, the complete element message in the element stack is popped from the stack and sent to the storage processor; the parent-child relationship message between the element number of the current level and the child element number of the child level is sent to the storage processor so that the storage processor can persist the complete element message according to the parent-child relationship message; the element number in the current level is placed into the current level in the level bucket and the element stack is popped.

[0077] Optionally, the document structure template records the elements that need to be focused on in the form of a node tree, with each node corresponding to an element tag in the XML document.

[0078] Optionally, the document processing module 230 is specifically used for:

[0079] When the XML document contains a document start tag, the event handler is triggered to send a document start event to the storage processor, so that the storage processor performs a storage initialization operation;

[0080] When a document termination tag is detected in the XML document, the event handler is triggered to send a document termination event to the storage processor, so that the storage processor performs storage cleanup actions.

[0081] The XML document parsing apparatus provided in this embodiment of the invention can execute the XML document parsing method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method execution.

[0082] Example 3

[0083] Figure 3 A schematic diagram of an electronic device 10 that can be used to implement embodiments 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 processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0084] like Figure 3 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0085] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0086] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as XML document parsing methods.

[0087] In some embodiments, the XML document parsing method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the XML document parsing method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the XML document parsing method by any other suitable means (e.g., by means of firmware).

[0088] Various embodiments 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-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting 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 implicitly included in a computer program product. When executed by a processor, the computer program implements the XML document parsing method of the present invention. The computer program product can be understood as a software product that primarily implements its solution through a computer program.

[0090] The computer program implementing the method of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer program causes the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer program can be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0091] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0092] To provide interaction with a user, the systems and techniques described herein can 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 pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0093] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0094] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0095] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0096] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. An XML document parsing method, characterized in that, include: The XML document is scanned line by line by the parser. When the XML document detects a trigger point for a target element event, the event handler processes the target element event and generates an element message. The event handler then sends the element message to the storage processor, enabling the storage processor to persist the target element event based on the element message. The element message represents a complete element and the relationships between elements. The target element event includes: an element start event, an element content event, and an element end event. The trigger point for the element start event is the element start tag; the trigger point for the element content event is the element text; and the trigger point for the element end event is the element end tag. The event handler includes an element stack, which records the order of elements and caches currently incomplete element text. When the trigger point of the target document event contained in the XML document is detected, the event handler is triggered to send the target document event to the storage processor so that the storage processor can persist the target document event. The step of triggering the event handler 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 detected, and sending the element message to the storage processor includes: When the XML document contains an element start tag, the event handler is triggered. If the element start tag is not recorded in the document structure template, a static general element is pushed onto 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 onto the element stack. The static general element is used to avoid confusion in the relationship between elements during the parsing process. When the XML document contains element text, 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 onto the element stack. When the XML document contains an element closing tag, 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 can persist the target element event based on the element message.

2. The XML document parsing method according to claim 1, characterized in that, The target document events include: document start event and document end event; the trigger point for the document start event is the document start tag, and the trigger point for the document end event is the document end tag.

3. The XML document parsing method according to claim 2, characterized in that, The event handler further includes a hierarchy bucket; the hierarchy bucket is used to store the element number and hierarchy of the currently unprocessed element.

4. The XML document parsing method according to claim 3, characterized in that, The step of triggering the event processor to generate an element message based on 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 popping the element stack so that the storage processor can persist the target element event based on the element message includes: If the element at the top of the element stack is recorded in the document structure template, and the element is compressed, then 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 of the hierarchical bucket. If the element is not compressed or decompressed, the complete element message in the element stack is popped from the stack and sent to the storage processor; the parent-child relationship message between the element number of the current level and the child element number of the child level is sent to the storage processor so that the storage processor can persist the complete element message according to the parent-child relationship message; the element number in the current level is placed into the current level in the level bucket and the element stack is popped.

5. The XML document parsing method according to any one of claims 4, characterized in that, The document structure template records the elements that need to be focused on in the form of a node tree, with each node corresponding to an element tag in the XML document.

6. The XML document parsing method according to claim 1, characterized in that, When a trigger point for a target document event is detected in the XML document, the step of triggering the event handler to send the target document event to the storage processor, so that the storage processor can persist the target document event, includes: When the XML document contains a document start tag, the event handler is triggered to send a document start event to the storage processor, so that the storage processor performs a storage initialization operation; When a document termination tag is detected in the XML document, the event handler is triggered to send a document termination event to the storage processor, so that the storage processor performs storage cleanup actions.

7. An XML document parsing apparatus, characterized in that, include: The scanning module is used to scan the XML document line by line using the parsing processor; The element processing module 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 detected, and send the element message to the storage processor so that the storage processor can perform persistent processing on the target element event based on the element message. The element messages are used to represent complete elements and the relationships between elements; wherein, the target element events include: element start event, element content event, and element end event; the trigger point for the element start event is the element start tag, the trigger point for the element content event is the element text, and the trigger point for the element end event is the element end tag; the event handler includes: an element stack; the element stack is used to record the order of elements and cache the text of elements that have not yet been fully processed; 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 detected, so that the storage processor can perform persistent processing on the target document event; The element processing module includes: The start tag processing unit is configured to trigger the event handler when the start tag of an element contained in the XML document is detected, and push the static general element onto the element stack if the start tag is not recorded in the document structure template; and assign an element number to the element marked by the start tag and push the element onto the element stack if the start tag is recorded in the document structure template. The element text processing unit is used to trigger the event handler when the element text contained in the XML document is scanned, and discard the element text if the top element of the element stack is not recorded in the document structure template; and push the element text onto the element stack if the top element of the element stack is recorded in the document structure template. The closing tag processing unit is configured to trigger the event handler when an element closing tag is detected in the XML document, and pop the element stack if the top element of the element stack is not recorded in the document structure template; if the top element of the element stack is recorded in the document structure template, generate an element message according to the compression state of the element, send the element message to the storage processor, and pop the element stack, so that the storage processor can persist the target element event based on the element message.

8. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the XML document parsing method according to any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the XML document parsing method according to any one of claims 1-6.

Citation Information

Patent Citations

  • JSAX (joint simple API (application program interface) for XML (extensible markup language)) parser and parsing method based on syntactic analysis of backtracking automaton

    CN102708155A

  • Quick query method for XML stream data

    CN107256218A

  • XML file reading method and device, equipment and storage medium

    CN116644213A

  • File analysis method and device, equipment and storage medium

    CN117435771A