CN102902732B - A kind of method of adding verification in XML configuration file - Google Patents

A kind of method of adding verification in XML configuration file Download PDF

Info

Publication number
CN102902732B
CN102902732B CN201210335361.2A CN201210335361A CN102902732B CN 102902732 B CN102902732 B CN 102902732B CN 201210335361 A CN201210335361 A CN 201210335361A CN 102902732 B CN102902732 B CN 102902732B
Authority
CN
China
Prior art keywords
configuration file
xml configuration
file
crc check
verification
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201210335361.2A
Other languages
Chinese (zh)
Other versions
CN102902732A (en
Inventor
刘永阳
肖家博
杨卫峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CRRC Zhuzhou Institute Co Ltd
Original Assignee
CSR Zhuzou Institute Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by CSR Zhuzou Institute Co Ltd filed Critical CSR Zhuzou Institute Co Ltd
Priority to CN201210335361.2A priority Critical patent/CN102902732B/en
Publication of CN102902732A publication Critical patent/CN102902732A/en
Application granted granted Critical
Publication of CN102902732B publication Critical patent/CN102902732B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a kind of method of adding verification in XML configuration file, in former XML configuration file, first add a verification element, obtain a new XML configuration file; Former XML configuration file is replaced by the new XML configuration file with verification element; Before using new XML configuration file, first new XML configuration file is verified, read the verification element information in new XML configuration file, recalculate the School Affairs of new XML configuration file, and more whether the School Affairs this calculated is consistent with the check information read, and ensures the correctness of XML configuration file with this.The present invention utilizes and add verification element in XML configuration file, can not destroy former XML configuration file structure, also can not affect program and run, can Timeliness coverage file accidental modification, prevent from using illegal XML configuration file, thus improve the reliability of system.

Description

A kind of method of adding verification in XML configuration file
Technical field
The present invention relates to a kind of verification XML(eXended Mark Language, extend markup language) method of configuration file, especially relate to and a kind of in XML configuration file, add verification, particularly CRC(Cyclic Redundancy Check, cyclic redundancy check (CRC)) method that verifies.
Background technology
XML language and extend markup language (Extensible Markup Language) be a kind of common markup language, and HTML are similar.XML language is mainly used in electroactive marker son file and makes it have structural markup language, can be used for flag data, definition data type, be the source language that the markup language of a kind of user of permission to oneself defines.Element is the most basic unit of composition XML, and it is by beginning label, attribute and end mark composition.As: <elementName att1Name=" att1Value " > is exactly the example of an element.Each element must have a masurium, and element can several attributes and property value.
A usual include file head of XML file and file body two large divisions.XML file head is stated and DTD(DocumentType Definition by XML, document type definition) Document Type Declaration composition.Wherein dtd file type declarations can lack, and introduce, and XML statement must have, with the standard specification making file meet XML about DTD statement by follow-up content.What comprise in XML file body is the content of XML file, and XML element is the elementary cell of XML file content.
CRC(Cyclic Redundancy Check, cyclic redundancy check (CRC)) be a kind of a kind of hash function producing brief fixing figure place check code according to the data such as network data package or computer archive, be mainly used to detect or checking data transmission or the mistake that may occur after preserving.Similar method of calibration also has the modes such as parity checking, cumulative sum verification, MD5.
Because XML file is flexible, be usually used in carrying out data transmission between various application program, use in information storage and description etc. and also widely use, the configuration file that the TRDP communication protocol that such as railway systems use uses is based on XML format.TRDP communication protocol is a complex protocol, need the parameter of configuration more, and these parameters all get inside XML configuration file, rewrite if XML configuration file meets accident or damage, so very likely can cause TRDP protocol configuration mistake, even cause train operation abnormal, therefore XML configuration file must be correctly available.
XML file has oneself specific file layout, such as all labels all must be closed, can only have a root element etc., at present in the application of general XML configuration file, verifying the correctness of XML file is generally use system function to judge that whether XML file form is correct, such as judges whether that all labels are all closedowns, whether only have a root element etc.
At present not to the integrity checking method of XML configuration file, and comparatively simple to the whether correct this judgment mode of file layout, can not guarantee that file content is correct.Such as: arbitrarily inside amendment XML file, element property values can't change file structure, it is still correct for returning results the judgement of file layout in this case, reliability in this way not high, correctness and the availability of XML configuration file can not be ensured.
Summary of the invention
The object of this invention is to provide a kind of method of adding verification in XML configuration file, the method can determine the validity of XML file, prevents from using illegal XML configuration file, thus improves the reliability of system.
In order to realize foregoing invention object, the present invention specifically provides a kind of technic relization scheme adding method of calibration in XML configuration file, and a kind of method of adding verification in XML configuration file, comprises the following steps:
S101: add a verification element in former XML configuration file, obtain a new XML configuration file;
S102: replace former XML configuration file by the new XML configuration file with verification element;
S103: before using new XML configuration file, first new XML configuration file is verified: read the verification element information in new XML configuration file, recalculate the School Affairs of new XML configuration file, and more whether the School Affairs calculated is consistent with the check information read, if consistent supporting paper is correct, ensure the correctness of XML configuration file.
As a kind of further improvement adding the method and technology scheme of verification in XML configuration file of the present invention, the method for adding verification can adopt the modes such as CRC check, parity checking or cumulative sum verification.
As a kind of further improvement adding the method and technology scheme of verification in XML configuration file of the present invention, the value of CRC check element be former XML configuration file CRC check and, before add CRC check element in former XML configuration file, first calculate former XML configuration file CRC check and.
As a kind of further improvement adding the method and technology scheme of verification in XML configuration file of the present invention, before using new XML configuration file, first read the CRC element information in new XML configuration file, more whether the School Affairs recalculating new XML configuration file is also consistent with the CRC element information in the XML configuration file read, and ensures the correctness of new XML configuration file.
As a kind of further improvement adding the method and technology scheme of verification in XML configuration file of the present invention, step S103 comprises following process further:
S1301: open the new XML configuration file needing verification;
S1302: search CRC element information, if do not found, illustrates that new XML configuration file is incorrect, returns mistake; If found, obtain CRC check and the X of XML configuration file from the text field of CRC element;
S1303: new XML configuration file is all read internal memory, obtains the length a of file;
S1304: search for CRC element in the file copy of internal memory, obtains the length b of CRC element, deletes CRC element;
S1305: calculate memory file copy CRC check and, computational length is a-b, the CRC check calculated and for Y;
S1306: whether unanimously compare X with Y, illustrate that new XML configuration file is correct if consistent, verification is passed through, otherwise XML configuration file verifies unsuccessfully.
As a kind of further improvement adding the method and technology scheme of verification in XML configuration file of the present invention, CRC check element is added on the afterbody of former XML configuration file.
As a kind of further improvement adding the method and technology scheme of verification in XML configuration file of the present invention, in step S101, PC adds CRC check element by tool software in former XML configuration file.
As a kind of further improvement adding the method and technology scheme of verification in XML configuration file of the present invention, calculate former XML configuration file CRC check and process and the process conformity that adds CRC check element in former XML configuration file carry out in a tool software.
As a kind of further improvement adding the method and technology scheme of verification in XML configuration file of the present invention, tool software performs following steps:
S1401: open XML configuration file;
S1402: the content of XML configuration file is all read in the middle of internal memory;
S1403: calculate internal memory file copy CRC check and, be X;
S1404: insert a CRC check element at the afterbody of the XML configuration file of internal memory, and element value is set to X;
S1405: create and export XML configuration file;
S1406: by the XML configuration file copy content in internal memory to output file;
S1407: close file.
By implementing a kind of technical scheme of adding the method for verification in XML configuration file of the invention described above, there is following technique effect:
(1) utilize the extensibility of XML file, the CRC element that interpolation one is new in XML configuration file, this element is used for the CRC check of file, and newly-increased CRC element both can not destroy former XML file structure, also can not affect the operation of program;
(2) usually verify XML configuration file by CRC unit whether to change, can amendment beyond Timeliness coverage XML configuration file, prevent from using illegal XML configuration file, thus improve the reliability of system.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present invention or technical scheme of the prior art, be briefly described to the accompanying drawing used required in embodiment or description of the prior art below, apparently, accompanying drawing in the following describes is only some embodiments of the present invention, for those of ordinary skill in the art, under the prerequisite not paying creative work, other accompanying drawing can also be obtained according to these accompanying drawings.
Fig. 1 is the file structure schematic diagram of prior art XML file;
Fig. 2 is the process schematic that the present invention adds a kind of embodiment of method of verification in XML configuration file;
Fig. 3 is the program flow diagram that the present invention adds a kind of embodiment of method of verification in XML configuration file;
Fig. 4 is the program flow diagram that the present invention adds the XML configuration file checking procedure in a kind of embodiment of method of verification in XML configuration file.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, be clearly and completely described the technical scheme in the embodiment of the present invention, obviously, described embodiment is only a part of embodiment of the present invention, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.
As shown in accompanying drawing 2 to accompanying drawing 4, give the present invention a kind of specific embodiment adding the method for verification in XML configuration file, below in conjunction with the drawings and specific embodiments, the invention will be further described.
A kind of embodiment of adding the method for verification in XML configuration file as shown in accompanying drawing 2 and accompanying drawing 3, comprises the following steps:
S101: add a CRC check element in former XML configuration file, obtains a new XML configuration file;
S102: replace former XML configuration file by the new XML configuration file with CRC check element;
S103: before using new XML configuration file, first new XML configuration file is verified: read the CRC element information in new XML configuration file, recalculate new XML configuration file CRC check and, and more whether the School Affairs this calculated is consistent with the CRC check information read, ensure the correctness of XML configuration file, thus ensure that whole XML configuration file is complete available.
In above-mentioned steps S101, the value of CRC check element be further former XML configuration file CRC check and, before add CRC check element in former XML configuration file, first calculate former XML configuration file CRC check and.Before using new XML configuration file, first read the CRC element information in new XML configuration file, more whether the School Affairs recalculating new XML configuration file is also consistent with the CRC element information in the XML configuration file read, and ensures the correctness of new XML configuration file.Special needs to be pointed out is, although itemize for CRC check in a specific embodiment and analyze technical scheme of the present invention, but the method for calibration wherein used includes but not limited to CRC check, the mode such as parity checking, cumulative sum verification can also be used.As: the low byte that cumulative sum verification obtains after referring to data (character) byte that cumulative all needs send or receive and (being greater than 255 parts to cast out).And parity checking refers to that the number of " 1 " in the numerical digit of one group of binary code that basis is transmitted is that odd number or even number verify.What adopt odd number is called odd, otherwise, be then called even parity check.
As shown in Figure 4, the proof procedure of the new XML configuration file in step S103 is further comprising the steps:
S1301: open the new XML configuration file needing verification;
S1302: search CRC element information, if do not found, illustrates that new XML configuration file is incorrect, returns mistake; If found, obtain CRC check and the X of XML configuration file from the text field of CRC element;
S1303: new XML configuration file is all read internal memory, obtains the length a of file;
S1304: search for CRC element in the file copy of internal memory, obtains the length b of CRC element, deletes CRC element;
S1305: calculate memory file copy CRC check and, computational length is a-b, the CRC check calculated and for Y;
S1306: whether unanimously compare X with Y, illustrate that new XML configuration file is correct if consistent, verification is passed through, otherwise XML configuration file verifies unsuccessfully.
As shown in Figure 2, CRC check element is added on the afterbody of former XML configuration file.In step S101, PC adds CRC check element by tool software in former XML configuration file.As one preferably embodiment, calculate former XML configuration file CRC check and process and the process conformity that adds CRC check element in former XML configuration file carry out in a tool software.
The treatment scheme of this tool software is:
S1401: open XML configuration file;
S1402: the content of XML configuration file is all read in the middle of internal memory;
S1403: calculate internal memory file copy CRC check and, be X;
S1404: insert a CRC check element at the afterbody of the XML configuration file of internal memory, and element value is set to X;
S1405: create and export XML configuration file;
S1406: by the XML configuration file copy content in internal memory to output file;
S1407: close file.
Be configured to example so that detailed process of the invention process to be described with XML typical in below, former XML configuration file (supposing that file is called example.xml) content is as follows:
The process implemented specifically is divided into adds School Affairs and file verification two steps to file, describes respectively below.
(1) School Affairs is added
Calculate above-mentioned file content CRC check and for 0xf75023b5, therefore can add CRC element at the afterbody of above-mentioned XML configuration file, obtain a new XML configuration file example2.xml, example2.xml file content is as follows:
Substitute original example.xml file with example2.xml file, namely formally use example2.xml file when using because in example2.xml file with the CRC check of self and, can be used for file verification.
Above-mentioned calculating CRC check and, add the function of new element and can be incorporated in the middle of a tool software further, directly use tool software to complete when in use, save hand computation and add the trouble of new element, more convenient.
(2) file verification process
Open example2.xml file, by the element of resolution file inside, search the element of element " CRC " by name and corresponding element value, the value for example2.xml file " CRC " element is 0xf75023b5, and namely the School Affairs of example.xml file should be 0xf75023b5.
Then be all read in the middle of internal memory by file content, delete CRC element, the file content in such internal memory is consistent with example.xml file content, by example2.xml file access pattern to example.xml file.
Call CRC check and computing function and CRC is calculated to the example.xml in the middle of internal memory, obtain a new CRC check and value, suppose that this value calculated is X, whether effectively so only need compare the whether equal just known file of this X and 0xf75023b5 calculated: if effectively equal, otherwise file there occurs change, be invalid.
The present invention utilizes XML element extensibility feature, in XML configuration file, add a new CRC element, by the CRC check of former XML configuration file be kept in the middle of this CRC element.In use, first read the CRC element information in XML configuration file, recalculate the School Affairs of XML configuration file and compare whether consistent with the information in CRC element, ensureing the correctness of XML configuration file, thus preventing the XML configuration file of mistake in from bringing hidden danger to system.
The present invention utilizes XML file to have the feature of extensibility: because have a lot of element in XML file, application program is only concerned about the element oneself needed, and the number of elements namely in configuration file can be more than needs.Therefore, add new CRC element in XML file after, former XML file structure can not be destroyed, also can not affect the operation of program.This newly-increased element can be used to verification file, can guarantee that XML file can not be illegally modified, and improves the reliability of system.
The above is only preferred embodiment of the present invention, not does any pro forma restriction to the present invention.Although the present invention discloses as above with preferred embodiment, but and be not used to limit the present invention.Any those of ordinary skill in the art, do not departing under technical solution of the present invention ambit, the Method and Technology content of above-mentioned announcement all can be utilized to make many possible variations and modification to technical solution of the present invention, or be revised as the Equivalent embodiments of equivalent variations.Therefore, every content not departing from technical solution of the present invention, according to technical spirit of the present invention to any simple modification made for any of the above embodiments, equivalent replacement, equivalence change and modification, all still belongs in the scope of technical solution of the present invention protection.

Claims (4)

1. in XML configuration file, add a method for verification, it is characterized in that, comprise the following steps:
S101: add a verification element in former XML configuration file, obtain a new XML configuration file;
S102: replace former XML configuration file by the new XML configuration file with verification element;
S103: before using new XML configuration file, first new XML configuration file is verified: read the verification element information in new XML configuration file, recalculate the School Affairs of new XML configuration file, and more whether the School Affairs calculated is consistent with the check information read, if consistent supporting paper is correct, ensure the correctness of XML configuration file with this;
Described method of adding verification adopts CRC check, the value of CRC check element be former XML configuration file CRC check and, before add CRC check element in former XML configuration file, first calculate former XML configuration file CRC check and;
Described CRC check element is added on the afterbody of former XML configuration file;
Described step S103 comprises following process further:
S1301: open the new XML configuration file needing verification;
S1302: search CRC element information, if do not found, illustrates that new XML configuration file is incorrect, returns mistake; If found, obtain CRC check and the X of XML configuration file from the text field of CRC element;
S1303: new XML configuration file is all read internal memory, obtains the length a of file;
S1304: search for CRC element in the file copy of internal memory, obtains the length b of CRC element, deletes CRC element;
S1305: calculate memory file copy CRC check and, computational length is a-b, the CRC check calculated and for Y;
S1306: whether unanimously compare X with Y, illustrate that new XML configuration file is correct if consistent, verification is passed through, otherwise XML configuration file verifies unsuccessfully.
2. a kind of method of adding verification in XML configuration file according to claim 1, is characterized in that: in described step S101, and PC adds CRC check element by tool software in former XML configuration file.
3. a kind of method of adding verification in XML configuration file according to claim 2, it is characterized in that: calculate former XML configuration file CRC check and process and the process conformity that adds CRC check element in former XML configuration file carry out in a tool software, by tool software complete CRC check and calculating and interpolation.
4. a kind of method of adding verification in XML configuration file according to Claims 2 or 3, is characterized in that, described tool software performs following steps:
S1401: open XML configuration file;
S1402: the content of XML configuration file is all read in the middle of internal memory;
S1403: calculate internal memory file copy CRC check and, be X;
S1404: insert a CRC check element at the afterbody of the XML configuration file of internal memory, and element value is set to X;
S1405: create and export XML configuration file;
S1406: by the XML configuration file copy content in internal memory to output file;
S1407: close file.
CN201210335361.2A 2012-09-11 2012-09-11 A kind of method of adding verification in XML configuration file Active CN102902732B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210335361.2A CN102902732B (en) 2012-09-11 2012-09-11 A kind of method of adding verification in XML configuration file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210335361.2A CN102902732B (en) 2012-09-11 2012-09-11 A kind of method of adding verification in XML configuration file

Publications (2)

Publication Number Publication Date
CN102902732A CN102902732A (en) 2013-01-30
CN102902732B true CN102902732B (en) 2015-09-02

Family

ID=47574965

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210335361.2A Active CN102902732B (en) 2012-09-11 2012-09-11 A kind of method of adding verification in XML configuration file

Country Status (1)

Country Link
CN (1) CN102902732B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103077097B (en) * 2013-02-25 2015-08-12 国电南瑞科技股份有限公司 A kind of FLASH data programming method based on verifying under TCP mode
CN106330966A (en) * 2016-10-24 2017-01-11 福建中金在线信息科技有限公司 Detection method and device for firewall configuration files
CN106874777A (en) * 2016-12-31 2017-06-20 惠州市蓝微新源技术有限公司 A kind of method and system for preventing configuration file to be tampered, monitoring host computer
CN109344129A (en) * 2018-08-16 2019-02-15 浙江众合科技股份有限公司 A kind of signal system configuration file generation system and method for high reliability
CN109919914B (en) * 2019-02-15 2021-04-13 广州视源电子科技股份有限公司 Configuration file checking method and device, computer equipment and storage medium
CN110765741A (en) * 2019-09-09 2020-02-07 重庆金融资产交易所有限责任公司 Data processing method and device, computer equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5991774A (en) * 1997-12-22 1999-11-23 Schneider Automation Inc. Method for identifying the validity of an executable file description by appending the checksum and the version ID of the file to an end thereof
CN1270346A (en) * 1999-04-13 2000-10-18 佳能株式会社 Digit processing method and apparatus
CN1770051A (en) * 2004-11-04 2006-05-10 华为技术有限公司 File safety detection method
CN102117299A (en) * 2009-12-30 2011-07-06 中兴通讯股份有限公司 System and method for importing configuration files in foreground

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7673231B2 (en) * 2005-06-24 2010-03-02 Sun Microsystems, Inc. Optimized markup language processing using repeated structures in markup language source

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5991774A (en) * 1997-12-22 1999-11-23 Schneider Automation Inc. Method for identifying the validity of an executable file description by appending the checksum and the version ID of the file to an end thereof
CN1270346A (en) * 1999-04-13 2000-10-18 佳能株式会社 Digit processing method and apparatus
CN1770051A (en) * 2004-11-04 2006-05-10 华为技术有限公司 File safety detection method
CN102117299A (en) * 2009-12-30 2011-07-06 中兴通讯股份有限公司 System and method for importing configuration files in foreground

Also Published As

Publication number Publication date
CN102902732A (en) 2013-01-30

Similar Documents

Publication Publication Date Title
CN102902732B (en) A kind of method of adding verification in XML configuration file
US11250210B1 (en) Systems and methods for providing a collaborative document environment
CN109375901A (en) Interface message management method, device, computer equipment and storage medium
Belhajjame et al. Prov-dm: The prov data model
CN110597814B (en) Structured data serialization and deserialization method and device
CN108268253A (en) Interface code generation method and terminal device
US20120066662A1 (en) System and method to validate and repair process flow drawings
CN114600420A (en) Pruning entries in a tamper-resistant data storage device
CN103605518A (en) Object deserialization method and device
CN104486075A (en) Intelligent substation ICD model file digital signature verification method
CN108647025A (en) Processing method and processing device, electronics and the storage device of DOM Document Object Model interior joint
CN107193570A (en) A kind of method and system for automatically generating API documents
CN103927385A (en) Unifying method and device of data model
TW201520813A (en) Anti-malware mobile content data management apparatus and method
CN107169000A (en) Static resource dissemination method and device
CN107608702A (en) Bootloader program modules update method and device
CN112989433A (en) Verification method based on Java Bean verification rule and related equipment
CN109753639B (en) Front-background unified verification method and device, storage medium and electronic equipment
US20110265058A1 (en) Embeddable project data
US10956659B1 (en) System for generating templates from webpages
CN110020413B (en) Method and device for detecting IMIX message and electronic equipment
CN111324645B (en) Block chain data processing method and device
KR102076558B1 (en) Apparatus for generating electronic document defined in open document format in consideration of compatibility with electronic document defined in non-open document format and operating method thereof
CN106156081A (en) A kind of list verifying method and equipment
CN109768853A (en) A kind of key component verification method, device and terminal device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant