CN104360890A - Method for generating XML file based on Java - Google Patents
Method for generating XML file based on Java Download PDFInfo
- Publication number
- CN104360890A CN104360890A CN201410555608.0A CN201410555608A CN104360890A CN 104360890 A CN104360890 A CN 104360890A CN 201410555608 A CN201410555608 A CN 201410555608A CN 104360890 A CN104360890 A CN 104360890A
- Authority
- CN
- China
- Prior art keywords
- xml
- xml file
- user
- data
- java
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Abstract
The invention discloses a method for generating an XML file based on Java. The method comprises the following steps: defining an XML format to generate an appointed XML file by a user, analyzing the condition format defined by the user by using a Java regular expression, traversing data to screen data which meet the conditions, adding into XML nodes, and generating attribute names and attribute values of the XML nodes according to a Java reflection mechanism. By adopting the method, XML files of user-defined data formats can be automatically generated, the function of customizing XML files is achieved, and when an XML file needs to be generated, the user only needs to call corresponding interfaces without rewriting codes, so that the encoding workload is reduced, and the working efficiency is improved.
Description
Technical field
The present invention relates to technical field of data processing, particularly relate to a kind of method generating XML file based on Java.
Background technology
XML is extend markup language, it 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, XML is the most frequently used instrument carrying out data transmission between various application program.It provide a kind of form of description scheme data, simplify exchanges data and expression in network, make code, data be separated with expression, and as the standard format of exchanges data, and form flexibly, the therefore instrument that transmitted as data by most of application system and website of XML.
The application for a patent for invention of CN201110042859.5 discloses a kind of XML file generation method and device, terminal device.Wherein, the method comprises: create XML file template, XML file template comprises: one or more file label; XML Core Generator is obtained according to the template of XML file; After XML Core Generator obtains input data, automatically generate XML file.By the present invention, resource content can be controlled flexibly according to demand, save the storage space of application, facilitate application and development and the content maintenance of image-text, improve the work efficiency of research staff.
Said method needs to create XML file template and use XML Core Generator to obtain input data and automatically could generate XML file, XML file cannot be generated according to the data of data base querying or user-defined XML format, underaction, does not accomplish to generate XML file completely automatically.
Summary of the invention
The object of the invention is the defect in order to overcome prior art, provide a kind of method generating XML file based on Java, the step of the method is as follows:
S1, arrange XML file store title;
S2, arrange XML file store coding;
S3, the title of definition XML root node and the title of XML child node;
S4, relation between XML parent node and sub-level node is set;
S5, Java regular expression is utilized to resolve user-defined data layout;
S6, to inquiry return data travel through;
The reflex mechanism of s7, Java is resolved data, and the attribute-name according to Java entity class generates the attribute-name of XML node and carries out assignment operation;
S8, judge whether current data meets user-defined condition, by qualified data supplementing in XML node, if do not met, then continue ergodic data;
S9, generation return an XML file.
The beneficial effect that technical solution of the present invention is brought:
The present invention can give and automatically generate the XML file that user defines data layout, realize the function that customization generates XML file, by arranging the relation between XML parent node and sub-level node, relation between automatic generation XML node, generate the XML file that user wants form, very flexible, user can find out the relation between data very intuitively, and stereovision is strong.When user wants to generate XML file, only need call corresponding interface, without the need to again writing code, reduce coding work amount, increasing work efficiency.
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 method flow diagram of the present invention.
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 the present invention's part embodiment, 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.
Main innovate point of the present invention is to generate XML file according to user-defined XML format.First the filename of XML is set, the coding that XML file stores is set, with UTF-8 code storage or with GBK code storage; The title of definition XML root node and the title of XML child node, create XML node according to user-defined nodename; Relation between XML parent node and sub-level node is set, relation at the same level or sub-level relation; The regular expression of Java is utilized to resolve user-defined data layout, Query Database, then travel through inquiring about the data returned according to the condition arranged, in the process of traversal, utilize the reflex mechanism of Java to resolve data, the attribute-name according to Java entity class generates the attribute-name of XML node and carries out assignment operation; Traversal process in, judge whether current data meets user-defined condition, if met, by qualified data supplementing to XML node in, if do not met, then continue ergodic data, until data traversal completes, finally generate and return the XML file of user's definition format.
Be illustrated in figure 1 method flow diagram of the present invention, implementation step is as follows:
(1) title that XML file stores is set;
(2) coding that XML file stores is set;
(3) title of XML root node and the title of XML child node is defined;
(4) relation between XML parent node and sub-level node is set;
(5) Java regular expression is utilized to resolve user-defined data layout;
(6) inquiry return data is traveled through;
(7) reflex mechanism of Java is resolved data, and the attribute-name according to Java entity class generates the attribute-name of XML node and carries out assignment operation;
(8) judge whether current data meets user-defined condition, by qualified data supplementing in XML node, if do not met, then continue ergodic data;
(9) generate and return an XML file.
By the invention solves in project the problem using XML file to carry out data interaction or data transmission.Because XML data form is flexible, changeable, can the title of oneself defined node, if just process all separately very time-consuming to the XML file of often kind of form, a kind of method generating XML file based on Java provided by the invention, the XML file of several data form can be generated, the title of XML node can also be defined according to user and the hierarchical relationship arranged between XML node generates XML file.
The present invention can also by generating multiple XML file, then need to be formed modifying to multiple XML according to user the XML file that user wants, or the XML file of format can also be there is no by generating, when user need specific just again on the basis of XML not having format at customized development.
Above a kind of method based on Java generation XML file that the embodiment of the present invention provides is described in detail, apply specific case herein to set forth principle of the present invention and embodiment, the explanation of above embodiment just understands method of the present invention and core concept thereof for helping; Meanwhile, for one of ordinary skill in the art, according to thought of the present invention, all will change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.
Claims (4)
1. one kind generates the method for XML file based on Java, it is characterized in that, the method generates the XML file of specifying by User Defined XML format, Java regular expression is utilized to resolve user-defined conditional formats, by filtering out qualified data supplementing to the traversal of data in XML node, utilize the reflex mechanism of Java to generate attribute-name and the property value of XML node, it comprises the steps:
S1, arrange XML file store title;
S2, arrange XML file store coding;
S3, the title of definition XML root node and the title of XML child node;
S4, relation between XML parent node and sub-level node is set;
S5, Java regular expression is utilized to resolve user-defined data layout;
S6, to inquiry return data travel through;
The reflex mechanism of s7, Java is resolved data, and the attribute-name according to Java entity class generates the attribute-name of XML node and carries out assignment operation;
S8, judge whether current data meets user-defined condition, by qualified data supplementing in XML node, if do not met, then continue ergodic data;
S9, generation return an XML file.
2. method according to claim 1, is characterized in that, the coding that XML file stores, can with UTF-8 code storage or with GBK code storage.
3. method according to claim 1, is characterized in that, the present invention can also by generating multiple XML file, then needs to be formed modifying to multiple XML according to user the XML file that user wants.
4. method according to claim 1, is characterized in that, the present invention can also not have the XML file of format by generating, when user need specific just again on the basis of XML not having format at customized development.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410555608.0A CN104360890A (en) | 2014-10-17 | 2014-10-17 | Method for generating XML file based on Java |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410555608.0A CN104360890A (en) | 2014-10-17 | 2014-10-17 | Method for generating XML file based on Java |
Publications (1)
Publication Number | Publication Date |
---|---|
CN104360890A true CN104360890A (en) | 2015-02-18 |
Family
ID=52528154
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410555608.0A Pending CN104360890A (en) | 2014-10-17 | 2014-10-17 | Method for generating XML file based on Java |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104360890A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105426480A (en) * | 2015-11-19 | 2016-03-23 | 中国地质大学(武汉) | Method and apparatus for converting HTML into Word document |
CN107220256A (en) * | 2016-03-22 | 2017-09-29 | 中电科海洋信息技术研究院有限公司 | Web front-end shows the automatic generation method of file |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101634942A (en) * | 2008-07-24 | 2010-01-27 | 北大方正集团有限公司 | Method and system for dynamically creating data tables |
CN101944133A (en) * | 2010-09-28 | 2011-01-12 | 山东中创软件工程股份有限公司 | XML metadata objectification analytic method and system |
CN102402541A (en) * | 2010-09-14 | 2012-04-04 | 捷达世软件(深圳)有限公司 | File analysis system and method |
-
2014
- 2014-10-17 CN CN201410555608.0A patent/CN104360890A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101634942A (en) * | 2008-07-24 | 2010-01-27 | 北大方正集团有限公司 | Method and system for dynamically creating data tables |
CN102402541A (en) * | 2010-09-14 | 2012-04-04 | 捷达世软件(深圳)有限公司 | File analysis system and method |
CN101944133A (en) * | 2010-09-28 | 2011-01-12 | 山东中创软件工程股份有限公司 | XML metadata objectification analytic method and system |
Non-Patent Citations (1)
Title |
---|
集微笔记: ""Java生成XML文档的基本操作"", 《WWW.360DOC.COM/CONTENT/13/0731/10/13247663_303740046.SHTML》 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105426480A (en) * | 2015-11-19 | 2016-03-23 | 中国地质大学(武汉) | Method and apparatus for converting HTML into Word document |
CN107220256A (en) * | 2016-03-22 | 2017-09-29 | 中电科海洋信息技术研究院有限公司 | Web front-end shows the automatic generation method of file |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106528129B (en) | A kind of Web application interface generation system and method | |
CN109062952B (en) | Data query method and device and electronic equipment | |
US9122770B2 (en) | System and method for creating, managing, and reusing schema type definitions in services oriented architecture services, grouped in the form of libraries | |
CN105022615A (en) | Interface generating method and system | |
US9342556B2 (en) | RDF graphs made of RDF query language queries | |
JP5672134B2 (en) | Method and apparatus for generating ontology documents | |
CN105843945A (en) | Report generation method and system | |
CN110609906B (en) | Knowledge graph construction method and device, storage medium and electronic terminal | |
US20170192776A1 (en) | Service interface creation and modification for object-oriented services | |
JP2012203860A (en) | Ontology updating device, method and system | |
CN102609506B (en) | Method for generating HL7 (Health Level 7) message through mapping | |
CN105760491A (en) | Data modeling method and device based on equipment functions | |
CN109582809A (en) | A kind of threedimensional model management system and method based on database | |
CN105893591B (en) | A kind of data sharing service intelligent arranging method | |
Heino et al. | Managing web content using linked data principles-combining semantic structure with dynamic content syndication | |
CN104360890A (en) | Method for generating XML file based on Java | |
WO2016201813A1 (en) | Dynamic layout method and system based on android | |
US9886424B2 (en) | Web application framework for extracting content | |
CN109522507A (en) | A kind of method of web pages component unified management | |
Brambilla et al. | Model-driven design of service-enabled web applications | |
CN111222015B (en) | Method for generating document by heterogeneous XML mapping | |
CN103488477A (en) | Visual editing system and visual editing method of JAVA interface | |
Mezei et al. | The dynamic sensor data description and data format conversion language. | |
CN109241158B (en) | Data source definition method and device for rule management | |
CN102253830B (en) | Method for automatically generating configuration file under Struts2 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20150218 |
|
WD01 | Invention patent application deemed withdrawn after publication |