A method for generating binary files based on XML deserialization and XML configuration

CN122547752APending Publication Date: 2026-08-11CASCO INTELLIGENT CONTROL (CHENGDU) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-25
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0007]为了克服上述现有技术中存在的缺陷,本发明公开了一种基于XML反序列化及XML配置生成二进制的模板方法,本发明的目的是解决现有技术中针对业务需求和输出语法部分紧密结合的问题

Benefits of technology

本发明解决了不同XML格式序列化的处理问题,并分离了XmlReader游标的移动和业务逻辑处理,使开发人员只需要在序列化的各自类中,只关注与业务逻辑,不需要关注游标的处理;同时通过配置的XML,分离了二进制文件的具体输出,不仅使开发人员更专注于逻辑实现,也增添了通用性,降低了输出各个字段的复杂性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122547752A_ABST
    Figure CN122547752A_ABST
Patent Text Reader

Abstract

This invention discloses a method for generating binary files based on XML deserialization and XML configuration, relating to the fields of data processing and text generation technology. The method includes: creating a base class `XmlBaseSerializable` that inherits the `IXmlSerializable` interface; defining template methods to control the movement of the `XmlReader` cursor and reserving hook functions; having business classes inherit from this base class and override the hook functions; obtaining input XML data through XML deserialization and storing it in memory; configuring independent XML output according to business requirements; defining the field names, types, byte counts, and endianness attributes of the binary file to be output; creating a `MemberOutput` class to parse the output XML; matching the business data in memory according to the field names; and outputting the binary file in sequence. This invention achieves the separation of the XML deserialization process from business logic, and the decoupling of output configuration from parsing logic, reducing development complexity and coupling, and improving versatility and maintainability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing and text generation technology, and more specifically to a method for generating binary files based on XML deserialization and XML configuration. Background Technology

[0002] In the field of urban rail transit, various subsystems need to operate and process data online. To reduce the amount of data computation during online operation, some specific data on the line can be processed offline, converted into binary files, and burned. Many offline data processing software programs need to perform specific line-specific logical processing on input files in XML format, and finally generate binary files according to the specific field byte counts for software use.

[0003] In the existing technology, the patent with publication number CN117632853A discloses a binary file generation method based on XML input file. This patent uses XSD verification, reads nodes through xmlReader object, obtains attribute values, enters each deserialization file, and writes the binary output of each part separately.

[0004] The patent with publication number CN110209389A discloses an XML-based data generation tool development system, which includes a programmable XML configuration script, an input adapter module, a data structure module, a general tool module, a data parsing module, an IOC attribute auto-assembly module, a script parsing module, a file output module, a class mapping module, a syntax intelligent prompting module, a script debugging module, and a runtime log output module. By building a unified data configuration tool development platform, the platform provides programming interfaces to the outside world in the form of XML scripts. In the XML scripts, a set of programmable script syntax is defined to help developers quickly and accurately develop secure data configurations.

[0005] Patent CN110209389A designs a complete set of programmable syntax. The business logic and programmable syntax are too closely related. When faced with complex logic, whether it can be handled and how efficient it is are still debatable. As for the programmable syntax, the learning cost is high and it is difficult for developers to get started.

[0006] Patent CN117632853A uses XML to output binary files. The business logic, reading the XmlReader cursor, and the output part are all combined, which is too coupled and not concise enough. Furthermore, it does not provide detailed instructions on how to handle semi-closed and closed tags in XML. Summary of the Invention

[0007] In order to overcome the defects in the prior art, the present invention discloses a method for generating binary templates based on XML deserialization and XML configuration. The purpose of the present invention is to solve the problem of tightly integrating business requirements and output syntax in the prior art. To achieve the above objectives, the technical solution adopted by the present invention is as follows: A method for generating binary files based on XML deserialization and XML configuration includes the following steps: 1. Create the XmlBaseSerializable base class S1. Create a base class XmlBaseSerializable that inherits the IXmlSerializable interface. This base class defines the template method ReadXml to control the movement of the XmlReader cursor and the node parsing process, and reserves hook functions. Preferably, the XmlBaseSerializable base class created in step S1 inherits the IXmlSerializable interface of the .NET framework, and the parameters of the template method ReadXml include an XmlReader cursor. This template method serves as the unified entry template method for XML deserialization, used to receive the XmlReader reader and start the entire XML node parsing process.

[0008] Preferably, the specific execution flow of the template method ReadXml includes: first, obtaining the depth of the node read by the current XmlReader and storing it as initialDepth, and at the same time obtaining the name of the current node and storing it as name; then, determining whether the current node has attributes, if so, calling the ReadAttributes hook function to execute the attribute reading logic, and after execution, moving the XmlReader cursor to the current element position; if the current node does not have attributes, directly moving the cursor to the current element position.

[0009] Preferably, after moving the cursor to the current element position, it checks whether the current node is an empty element: if it is an empty element, the EndExecute hook function is executed and the previous call is returned; if it is not an empty element, the XmlReader.Read function is executed in a loop to move the cursor to the next node. When the moved node is not empty, it checks whether the depth of the current node is equal to the initialDepth and whether the node name is equal to the name. If so, the loop is exited and the EndExecute hook function is executed. Otherwise, the NodeType of the current node is further checked.

[0010] Preferably, when determining the NodeType of the current node: if NodeType is XmlNodeType.Text or XmlNodeType.Whitespace, the ReadValue hook function is called to read the text value, and then the loop continues; if NodeType is XmlNodeType.Element, the ReadElement hook function is called to read the child element node, and then the loop continues; when the loop exits naturally because XmlReader.Read returns null, the EndExecute hook function is executed to complete the parsing of the current node and return to the previous call.

[0011] II. Creating Serialization Logic S2. Based on the data structure of the input XML, make the business-related classes inherit the XmlBaseSerializable base class created in step S1, and override the hook functions in the base class that match the business requirements; based on the hook functions, obtain the specific values ​​of each node, attribute and text in the input XML through XML deserialization, implement the business logic in the business-related classes, and store the obtained data set in memory; Preferably, step S2 includes: after the business-related class inherits the XmlBaseSerializable base class, it reuses the general parsing logic of the base class, eliminating the need to repeatedly develop cursor movement and node traversal functions; the ReadAttributes, ReadValue, ReadElement and EndExecute hook functions in the base class are rewritten as needed, and the specific values ​​of each node, attribute and text in the input XML file are accurately extracted through the hook functions, and the data validation and data conversion business logic is integrated in the business-related class, and the parsed business data is bound to the business class and stored in memory.

[0012] III. Configure XML output S3. Configure an independent output XML according to business needs. This output XML defines the field names, types, number of bytes, and endianness attributes of the binary file to be output. Preferably, the root node tag of the output XML configured in step S3 is... <outputfilelist>The <outputfilelist>Contains at least one sub-tag <outputfile>The <outputfile>The child tag contains a path attribute and an Endian attribute. The path attribute is used to specify the path of the output binary file, and the Endian attribute is used to specify the basic endianness setting of the file. The fields in the child node can be set independently to override the basic endianness setting.

[0013] Preferably, the <outputfile>The child nodes consist of at least one <member>The nodes constitute, the <member>The node includes `name`, `type`, `Endian`, and `ByteCount` attributes. The `name` attribute represents the name of the member variable to be output in the deserialization class; the `type` attribute represents the output type; the `Endian` attribute sets the endianness of the field; and the `ByteCount` attribute represents the number of bytes to output. The `type` attribute can take the following values: `SIZE`, indicating the number of bytes in all child nodes under this node; `Array`, indicating that the field is output as an array for multiple fields; and `compose`, indicating a composite data type containing multiple subfields but output as a single field and its value. <member>Nodes can be nested to express complex data structures.

[0014] IV. Parse and generate the output binary file S4. Create a MemberOutput class, parse the output XML configured in step S3 to generate the corresponding MemberOutput object, match the fields with the same name in the business data set stored in memory in step S2 according to the field names in the object, retrieve the values, and output them in order as a binary file.

[0015] Preferably, the MemberOutput class in step S4 includes the following member variables: a string variable `name` for storing field names, a boolean variable `bigEndian` for storing endianness settings, and a List for storing the collection of subfields. <memberoutput>The variable `memberList` is of type `member`, the variable `byteCount` is of type `int` used to store the number of bytes to be output, and the variable `List` is used to store the values ​​of the fields. <byte>The type variable is value, and the output flag variable is used to indicate whether output is required.

[0016] Preferably, step S4 specifically includes: parsing the output XML file configured in step S3, and processing each element in the output XML. <member>Each node creates a corresponding MemberOutput object. The value of the configured ByteCount property determines whether the node should perform an output operation. All created MemberOutput objects and their subfields are traversed. The field names in the MemberOutput objects are retrieved, and fields with the same names are matched in the business data set stored in memory in step S2. The specific attributes and values ​​of these fields are then retrieved and stored in the value member variable of the corresponding MemberOutput object. All final data that meets the output conditions is collected and stored in a List of the first-level MemberOutput class under the root node. <byte>In value, the data of this collection is output to the binary file specified by the path attribute in step S3, according to the traversal order.

[0017] The beneficial effects of this invention are: This invention solves the problem of serializing different XML formats and separates the movement of the XmlReader cursor from the business logic processing. This allows developers to focus only on the business logic within their respective serialization classes and not on cursor processing. At the same time, by configuring XML, the specific output of the binary file is separated, which not only allows developers to focus more on the logic implementation but also increases versatility and reduces the complexity of the output fields. Attached Figure Description

[0018] Figure 1 An overall block diagram for generating binary files for this invention; Figure 2 This is a flowchart of the ReadXml process of this invention. Detailed Implementation

[0019] The following will provide a clear and complete description of the concept, specific structure, and technical effects of the present invention in conjunction with the embodiments and accompanying drawings, so as to fully understand the purpose, features, and effects of the present invention.

[0020] A method for generating binary files based on XML deserialization and XML configuration, such as... Figure 1 As shown, it includes the following steps: 1. Create the XmlBaseSerializable base class S1. Create a base class `XmlBaseSerializable`, which inherits the `IXmlSerializable` interface and is used to implement the movement of the `XmlReader` cursor and basic calls. Here, `XmlBaseSerializable` represents a custom XML serialization base class, encapsulating common logic for subclasses to inherit; `IXmlSerializable` represents the .NET official XML serialization interface, defining standard rules for custom serialization; and `XmlReader` represents the .NET XML reading tool, which reads XML data using a cursor and is the core component for deserialization. Step S1 includes: setting the template method function ReadXml, with the parameter being the XmlReader cursor, which serves as the entry function; where ReadXml represents the unified entry template method for XML deserialization, used to receive the XmlReader reader and start the entire XML node parsing process.

[0021] Step S1 includes: First, the template method obtains the depth and name of the current node, then determines whether the node has attributes. If it does, the ReadAttributes hook function is executed. After execution, the XmlReader cursor is moved to the element. Here, ReadAttributes means reading the values ​​of all attributes under each specific node.

[0022] Step S1 includes: After executing the attribute part, determine whether the element where the cursor is located is an empty element. If it is empty, execute the EndExecute hook function; if it is not empty, execute the XmlReader.Read function in a loop. When it is not empty, if the depth of the current XmlReader node is the same as the depth when it was first entered into the ReadXml function, and the cursor name of the XmlReader node is the same as the name when it was first entered into the ReadXml function, then exit the loop. Here, EndExecute indicates that after the current node is executed, further processing is required, which is reserved for future use and can be used for checking; XmlReader.Read indicates that the XmlReader reading cursor is moved from the current node to the next node, realizing the node-by-node traversal reading of the XML document.

[0023] Step S1 includes: if the NodeType of the XmlReader node is of type XmlNodeType.Text or XmlNodeType.Whitespace, then the ReadValue hook function is executed; if XmlReader.NodeType is an element type, then the ReadElement hook function is executed; where NodeType represents an enumeration constant used to identify the type of the XML node; XmlNodeType.Text represents the text node type used to store the actual text content of the XML element; XmlNodeType.Whitespace represents the whitespace node type used to identify spaces, newlines, and tabs in the XML structure; ReadValue represents the hook method for reading and processing the text content in the current XML node; XmlReader.NodeType represents the type attribute used to get the node pointed to by the current XmlReader cursor; and ReadElement represents the hook method for reading and parsing the child element nodes under the current node.

[0024] In summary, as Figure 2 As shown, in step S1, the specific process of the template method ReadXml includes: S11. Get the node depth of the current XmlReader cursor and store it as initialDepth, and at the same time get the name of the current node and store it as name; S12. Determine if the current node has attributes: If it does, call the ReadAttributes hook function to read the attributes, and then move the cursor to the current element's position; if it does not, move the cursor directly to the current element's position. S13. Determine if the current node is an empty element: if it is an empty element, jump to S17; if it is not an empty element, proceed to S14. S14. Execute the XmlReader.Read function repeatedly to move the cursor to the next node and check if the current node is empty: if it is not empty, proceed to S15; if it is empty, exit the loop and jump to S17. S15. Determine if the depth of the current node is equal to initialDepth and if the node name is equal to name: If yes, exit the loop and jump to S17; otherwise, proceed to S16. S16. Determine the NodeType of the current node: If it is XmlNodeType.Text or XmlNodeType.Whitespace, call the ReadValue hook function to read the text value, and return to S14 after execution; if it is XmlNodeType.Element, call the ReadElement hook function to read the child element node, and return to S14 after execution. S17. Execute the EndExecute hook function to return to the previous level after completing the parsing of the current node.

[0025] In step S1, a unified base class XmlBaseSerializable is constructed to encapsulate common parsing logic such as XmlReader cursor movement, node traversal, attribute reading, and node type judgment. By combining template methods and hook methods, the fixed parsing process is separated from the subclass custom extension logic, thereby achieving standardization and scalability of the XML deserialization process.

[0026] In this invention, the purpose of step S1 is to provide a general, standardized, and extensible XML deserialization framework, simplify the development cost of subclasses implementing custom XML serialization, avoid repeatedly writing cursor control and node parsing code, ensure the stability, accuracy, and consistency of the XML parsing process, and improve the efficiency and maintainability of XML data processing.

[0027] II. Creating Serialization Logic S2. Based on the specific data structure in the XML file, parse it and write the corresponding data node parsing function; by having business-related classes inherit the XmlBaseSerializable base class, override the hook function in the base class that matches the business requirements, and use the hook function to accurately obtain the specific values ​​of each node, attribute and text in the XML file, and implement the corresponding business logic in the corresponding class; In step S2, the common parsing logic of the XmlBaseSerializable base class from step S1 is reused, eliminating the need to repeatedly develop basic functions such as cursor movement and node traversal, thus reducing code redundancy. Specifically, the structure and format of the input XML file are parsed, and appropriate node parsing functions are written; business classes inherit from this base class, and hook functions such as ReadAttributes are overridden as needed to accurately extract XML data; the parsed data is bound to the business classes, integrating business logic such as data validation and transformation, thereby achieving business-oriented reuse of XML data.

[0028] In this invention, the purpose of step S2 is to adapt XML parsing to business scenarios based on the general framework of step S1, solving the problem of adapting general parsing to personalized needs. By inheriting the base class and overriding hook functions, coupling is reduced, ensuring parsing accuracy and efficiency, and realizing the transformation of XML data into business-usable data, meeting the serialization and data application needs of various business scenarios.

[0029] III. Configure XML output S3. Configure the output XML according to business requirements; Preferably, in step S3, the XML output configured according to business requirements includes: the root node tag is <outputfilelist>It contains multiple sub-tags <outputfile>,exist <outputfile>The child tag contains the path and Endian attributes; <outputfile>The child nodes are <member>Node composition, <member>The node contains the attributes name, type, Endian, and ByteCount; The system consists of the following nodes: `OutputFileList` (root node) represents the output; `OutputFile` nodes represent the detailed content of the binary files to be output; `path` represents the path to the output file; `Endian` represents the endianness setting (if an attribute of the `OutputFile` node, it indicates the basic endianness setting of the file, and more detailed fields can be set manually); `member` represents the specific output fields, which can be nested; `name` represents the name of the member variable to be output in the serialization class; `type` represents the data type (if it's `SIZE`, it indicates the number of bytes in all nodes under this node; if it's `Array`, it indicates that the field is output as an array containing multiple fields; if it's `compose`, it represents a data type that can contain multiple fields for output, but only a single field and a numerical value can be output); and `ByteCount` represents the number of bytes to output. The relationship between steps S3 and S2 is as follows: Step S2 completes the parsing of the input XML data and the implementation of business logic, storing the parsed business data in the corresponding data structure; Step S3, based on this business data and combined with the actual business output requirements, configures the detailed fields and structure of the output XML, realizes the conversion of business data into XML output in the specified format, provides a clear configuration basis for subsequent binary file output, and together with Step S2, constitutes the XML serialization parsing and output configuration link.

[0030] In step S3, based on the business data parsed in step S2, the hierarchy, nodes, and attribute information of the output XML are configured according to the preset XML node structure and attribute definitions. The specific meaning and value rules of each node and attribute are clarified to ensure that the structure of the output XML is standardized, the content is accurate, and it is precisely matched with the business requirements and the business data in step S2. At the same time, through the flexible configuration of node attributes, the personalized adaptation of the output XML is realized to meet the output configuration requirements of different business scenarios.

[0031] In this invention, the purpose of step S3 is to define the structure and content of the output XML according to the business requirements based on the business data parsing results of step S2, realize the transformation of business data into standardized output XML, clarify the nodes, attributes and value rules of the output XML, meet the personalized needs of business scenarios for XML output format and content, improve the complete process of XML serialization from input parsing to output configuration, enhance the integrity and practicality of serialization processing, and provide standardized configuration support for subsequent binary file output.

[0032] IV. Parse and generate the output binary file S4. Create the MemberOutput class. This class encapsulates output field information, associates deserialized data with output configuration, and implements binary file output. It includes endianness indicators (bool bigEndian) and a collection of subfields (List). <memberoutput>memberList), output byte count (int byteCount), field name (stringname), output binary array (List <byte>The list includes member variables such as `value` and an output flag (whether to output); among them, `string name` is used to store the field name, `bool bigEndian` is used to store the endianness setting, and `List...` <memberoutput>`memberList` is used to store the collection of subfields, and `int byteCount` is used to store the number of bytes to be output. (List...) <byte>The `value` property is used to store field values. This class is mainly used to parse and store the specific content of the output XML file configured in step S3. At the same time, it retrieves all data sets from the deserialized structure, matches the member variables in S2 with the `name` value in the XML configuration file, retrieves their attributes and values, and saves them. Finally, it outputs a binary file.

[0033] Step S4 includes: traversing all created MemberOutput classes and their subfields, obtaining the field names in the MemberOutput class, matching fields with the same name in all business data sets parsed in step S2, obtaining the specific attributes and values ​​of the field and storing them in the corresponding MemberOutput class, and outputting all field data to the specified binary file in the traversal order.

[0034] Step S4 includes: each <member>Each node corresponds to a MemberOutput class. The value of the ByteCount node is used to determine whether the node should perform an output operation. All final data that meets the output conditions are collected and stored in a List of the first-level MemberOutput class under the root node. <byte>In the `value` field, the final output of this collection of data is the required binary file; where `List`... <byte>The value represents a set used to uniformly store all binary data to be output, and is used to collect various types of output data that meet the conditions, providing a unified data carrier for the subsequent one-time generation of binary files.

[0035] The relationship between step S4 and step S3 (or S2) is as follows: step S2 completes the parsing of the input XML data and stores the business data in the memory data structure; step S3 completes the configuration of the output XML and specifies the output fields, rules, and structure; step S4 uses the output XML configured in step S3 as the basis for parsing, uses the business data stored in step S2 as the data source, parses the output XML through the MemberOutput class, matches the business data, and finally generates a binary file, thus connecting steps S2 and S3 and forming a complete closed loop of XML serialization from parsing, configuration to output.

[0036] In step S4, first create the MemberOutput class and define its member variables. Based on the output XML file configured in step S3, for each... <member>Instantiate the corresponding MemberOutput object for each node; iterate through all MemberOutput classes and their subfields, and based on their name member variable, match the field name with the same name in the data set stored in memory in step S2, extract the specific attributes and values ​​of the field and store them in the value member variable of the corresponding MemberOutput class; according to the traversal order, output the data set as a binary file at the specified path, completing the conversion of business data to a binary file.

[0037] In this invention, the purpose of step S4 is to connect steps S2 and S3, and to realize the parsing of output XML, matching of business data, and generation of binary files through the MemberOutput class; to solve the technical problems of disconnect between output XML and business data, lack of unified encapsulation of binary output and data aggregation, to ensure that the matched business data is consistent with the output configuration, and that the output binary file meets business requirements, thus completing the complete process of XML serialization from data parsing and configuration to final output, and improving the practicality, stability and feasibility of serialization processing.

[0038] The embodiments of the present invention have been described in detail above, but the present invention is not limited to the described embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention, and these equivalents or substitutions are all included within the scope defined by the claims of the present invention.< / member> < / byte> < / byte> < / member> < / byte> < / memberoutput> < / byte> < / memberoutput> < / member> < / member> < / outputfile> < / outputfile> < / outputfile> < / outputfilelist> < / byte> < / member> < / byte> < / memberoutput> < / member> < / member> < / member> < / outputfile> < / outputfile> < / outputfile> < / outputfilelist> < / outputfilelist>

Claims

1. A method for generating a binary file based on XML deserialization and XML configuration, characterized in that, Includes the following steps: S1. Create a base class XmlBaseSerializable that inherits the IXmlSerializable interface. This base class defines the template method ReadXml to control the movement of the XmlReader cursor and the node parsing process, and reserves hook functions. S2. Based on the data structure of the input XML, make the business-related classes inherit the XmlBaseSerializable base class created in step S1, and override the hook functions in the base class that match the business requirements; based on the hook functions, obtain the specific values ​​of each node, attribute and text in the input XML through XML deserialization, implement the business logic in the business-related classes, and store the obtained data set in memory; S3. Configure an independent output XML according to business needs. This output XML defines the field names, types, number of bytes, and endianness attributes of the binary file to be output. S4. Create a MemberOutput class, parse the output XML configured in step S3 to generate the corresponding MemberOutput object, match the fields with the same name in the business data set stored in memory in step S2 according to the field names in the object, retrieve the values, and output them in order as a binary file.

2. The method for generating binary files based on XML deserialization and XML configuration according to claim 1, wherein, The XmlBaseSerializable base class created in step S1 inherits the IXmlSerializable interface of the .NET framework. The parameters of the template method ReadXml include an XmlReader cursor. This template method serves as the unified entry template method for XML deserialization, used to receive the XmlReader reader and start the entire XML node parsing process.

3. The method for generating binary files based on XML deserialization and XML configuration of claim 1, wherein, The specific execution flow of the template method ReadXml includes: first, obtaining the depth of the node read by the current XmlReader and storing it as initialDepth, and at the same time obtaining the name of the current node and storing it as name; then, determining whether the current node has attributes. If it does, the ReadAttributes hook function is called to execute the attribute reading logic. After execution, the XmlReader cursor is moved to the current element position; if the current node does not have attributes, the cursor is moved directly to the current element position.

4. The method for generating binary files based on XML deserialization and XML configuration of claim 3, wherein, After moving the cursor to the current element position, check if the current node is an empty element: if it is an empty element, execute the EndExecute hook function and return to the previous call level; if it is not an empty element, loop through and execute the XmlReader.Read function to move the cursor to the next node. When the moved node is not empty, check if the current node depth is equal to initialDepth and if the node name is equal to name. If so, break out of the loop and execute the EndExecute hook function. Otherwise, further check the NodeType of the current node.

5. The method for generating binary files based on XML deserialization and XML configuration of claim 4, wherein, When determining the NodeType of the current node: if NodeType is XmlNodeType.Text or XmlNodeType.Whitespace, the ReadValue hook function is called to read the text value, and then the loop continues; if NodeType is XmlNodeType.Element, the ReadElement hook function is called to read the child element node, and then the loop continues; when the loop exits naturally because XmlReader.Read returns null, the EndExecute hook function is executed to complete the parsing of the current node and return to the previous call.

6. The method for generating binary files based on XML deserialization and XML configuration of claim 1, wherein, Step S2 includes: after the business-related classes inherit the XmlBaseSerializable base class, they reuse the general parsing logic of the base class, eliminating the need to repeatedly develop cursor movement and node traversal functions; the ReadAttributes, ReadValue, ReadElement and EndExecute hook functions in the base class are rewritten as needed, and the specific values ​​of each node, attribute and text in the input XML file are accurately extracted through the hook functions, and the data validation and data conversion business logic is integrated in the business-related classes, and the parsed business data is bound to the business class and stored in memory.

7. The method for generating binary files based on XML deserialization and XML configuration as described in claim 1, characterized in that, The root node tag of the output XML configured in step S3 is... <outputfilelist>The <outputfilelist>Contains at least one sub-tag <outputfile>; the <outputfile> The child tag contains a path attribute and an Endian attribute. The path attribute is used to specify the path of the output binary file, and the Endian attribute is used to specify the basic endianness setting of the file. The fields in the child node can be set independently to override the basic endianness setting.< / outputfile> < / outputfile> < / outputfilelist> < / outputfilelist> 8. The method for generating binary files based on XML deserialization and XML configuration as described in claim 7, characterized in that, The <outputfile>The child nodes consist of at least one <member>The nodes constitute, the <member>The node includes `name`, `type`, `Endian`, and `ByteCount` attributes. The `name` attribute represents the name of the member variable to be output in the deserialization class; the `type` attribute represents the output type; the `Endian` attribute sets the endianness of the field; and the `ByteCount` attribute represents the number of bytes to output. The `type` attribute can take the following values: `SIZE`, indicating the number of bytes in all child nodes under this node; `Array`, indicating that the field is output as an array for multiple fields; and `compose`, indicating a composite data type containing multiple subfields but output as a single field and its value. <member> Nodes can be nested to express complex data structures.< / member> < / member> < / member> < / outputfile> 9. The method for generating binary files based on XML deserialization and XML configuration as described in claim 1, characterized in that, The MemberOutput class in step S4 contains the following member variables: a string variable `name` to store field names, a boolean variable `bigEndian` to store endianness settings, and a List to store the collection of subfields. <memberoutput>a type variable memberList, an int type variable byteCount for storing the number of bytes to be output, a List <byte> The type variable is value, and the output flag variable is used to indicate whether output is required.< / byte> < / memberoutput> 10. The method for generating binary files based on XML deserialization and XML configuration as described in claim 1, characterized in that, The S4 step specifically includes: parsing the output XML file configured in the S3 step, and processing each element in the output XML. <member>Each node creates a corresponding MemberOutput object. The value of the configured ByteCount property determines whether the node should perform an output operation. All created MemberOutput objects and their subfields are traversed. The field names in the MemberOutput objects are retrieved, and fields with the same names are matched in the business data set stored in memory in step S2. The specific attributes and values ​​of these fields are then retrieved and stored in the value member variable of the corresponding MemberOutput object. All final data that meets the output conditions is collected and stored in a List of the first-level MemberOutput class under the root node. <byte> In value, the data of this collection is output to the binary file specified by the path attribute in step S3, according to the traversal order.< / byte> < / member>

Citation Information

Patent Citations

  • XML-based data generation tool development system

    CN110209389A

  • Binary file generation method based on xml input file

    CN117632853A