当前位置:网站首页>[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
2022-07-06 00:34:00 【Programmer community】
One 、 Use MarkupBuilder Generate xml data
Generate
<student> <name code="utf-8">Tom</name> <age>18</age></student>
Styling xml file ,
First , establish FileWriter object , Then used to generate xml Data output to file ;
def fileWriter = new FileWriter(new File("a.xml"))
then , establish MarkupBuilder object , Constructor passed in FileWriter It means that you will xml Write the file into the file ;
// establish MarkupBuilder object // Constructor passed in FileWriter It means that you will xml Write the file into the file def markupBuilder = new MarkupBuilder(fileWriter)
Last , Generate xml data ;
// Generate the above xml file markupBuilder.student{
// The format is as follows : // xml Tag name ( Label content , Tag attributes : Tag attribute value ) // Generate label content : Just write the label directly // Generate tag attributes : Tag attributes are generated using key value pairs name("Tom", code: "utf-8") {
} age(18) {
}}
Here's a detailed introduction xml Data generation process ,
markupBuilder.student
Express , Generated xml The root node of the data is <student></student>
,
xml In the data label The generation format is as follows :
xml Tag name ( Label content , Tag attributes : Tag attribute value )
Generate label content : The label content can be written directly in brackets ;
age(18){}
Code can be generated<age>18</age>
Content ;Generate tag attributes : Tag attributes are generated using key value pairs ;
name("Tom", code: "utf-8") {}
Code can be generated<name code="utf-8">Tom</name>
Content ;
Two 、 Complete code example
Complete code example :
import groovy.xml.MarkupBuilder"""<student> <name code="utf-8">Tom</name> <age>18</age></student>"""def fileWriter = new FileWriter(new File("a.xml"))// establish MarkupBuilder object // Constructor passed in FileWriter It means that you will xml Write the file into the file def markupBuilder = new MarkupBuilder(fileWriter)// Generate the above xml file markupBuilder.student{
// The format is as follows : // xml Tag name ( Label content , Tag attributes : Tag attribute value ) // Generate label content : Just write the label directly // Generate tag attributes : Tag attributes are generated using key value pairs name("Tom", code: "utf-8") {
} age(18) {
}}
Generated xml The documents are as follows :
<student> <name code='utf-8'>Tom</name> <age>18</age></student>
The following figure , On the right side of the a.xml That's generated xml file ;
边栏推荐
- Leetcode:20220213 week race (less bugs, top 10% 555)
- What is information security? What is included? What is the difference with network security?
- MySql——CRUD
- Idea远程提交spark任务到yarn集群
- Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters
- Model analysis of establishment time and holding time
- uniapp开发,打包成H5部署到服务器
- Global and Chinese market of valve institutions 2022-2028: Research Report on technology, participants, trends, market size and share
- 多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
- [Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
猜你喜欢
About the slmgr command
小程序技术优势与产业互联网相结合的分析
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4
STM32 configuration after chip replacement and possible errors
MySql——CRUD
Extension and application of timestamp
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
Room cannot create an SQLite connection to verify the queries
Key structure of ffmpeg - avformatcontext
随机推荐
[designmode] Decorator Pattern
Go learning --- read INI file
Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4
Browser local storage
Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)
MySQL functions
[designmode] adapter pattern
XML Configuration File
wx. Getlocation (object object) application method, latest version
LeetCode 1598. Folder operation log collector
免费的聊天机器人API
JS can really prohibit constant modification this time!
NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
AtCoder Beginner Contest 258【比赛记录】
Global and Chinese markets for pressure and temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
Browser reflow and redraw
Codeforces round 804 (Div. 2) [competition record]
Spark DF adds a column
Single source shortest path exercise (I)