当前位置:网站首页>XMLBean的基础运用
XMLBean的基础运用
2022-07-30 05:44:00 【victorkevin】
- 根据xml schema生成xml
- Schema文件定义如下:
- xml version="1.0" encoding="UTF-8"?>
- <xs:schema xmlns="http://mydomain.com/myApp" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://mydomain.com/myApp" elementFormDefault="qualified" attributeFormDefault="unqualified">
- <xs:element name="e1">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="e11" type="xs:int"/>
- <xs:element name="e12">
- <xs:complexType>
- <xs:attribute name="e121" type="xs:string" use="required"/>
- <xs:attribute name="e122" type="xs:long"/>
- xs:complexType>
- xs:element>
- xs:sequence>
- xs:complexType>
- xs:element>
- xs:schema>
- 请用xmlBean生成jar包,并编写一个程序生成一个xml文件,其中e11=11 e121=”e121”。
PS:输入如下命令之前,务必设置好环置变量
命令如下:
Scomp –src build\src –out build\myApp.jar myApp.xsd
如果成功运行,在当前目录下会生成一个myApp.jar文件,然后把它添加到classpath下
- 程序如下:
- 注— Version xmlbeans-2.3.0 程序经过测试成功
- import com.mydomain.myApp.*;
- import com.mydomain.myApp.impl.*;
- import org.apache.xmlbeans.XmlOptions;
- import java.io.*;
- public class MyAppDemo{
- public static void main(String[] args)throws Exception{
- .E1Document e1Doc=E1Document.Factory.newInstance();
- E1Document.E1 e1=e1Doc.addNewE1();
- e1.setE11(11);
- E1Document.E1.E12 e12=e1.addNewE12();
- e12.setE121("e121");
- File file=new File("myApp.xml");
- e1Doc.save(file);
- }
- }
边栏推荐
猜你喜欢
Conda 安装 tensorflow gpu 1.13.1(验证可行)
Bypassing the file upload vulnerability
"MySQL Advanced Chapter" four, the storage structure of the index
【MySQL功法】第5话 · SQL单表查询
Use kotlin to extend plugins/dependencies to simplify code (after the latest version 4.0, this plugin has been deprecated, so please choose to learn, mainly to understand.)
Jdbc & Mysql timeout analysis
Nodejs PM2 monitoring and alarm email (2)
MySQL 索引的数据结构及类型
原型模式(Prototype):Swift 实现
十四、Kotlin进阶学习:一、内联函数 inline;二、泛型;三、泛型约束;四、子类与子类型;
随机推荐
GraphQL (1) Basic introduction and application examples
The number of warehouse 】 data quality
树莓派OpenCV+OpenCV-contrib
awd --waf deployment
Jdbc & Mysql timeout分析
Function functional interface and application
Flink-流/批/OLAP一体得到Flink引擎
sql concat() function
JVM学习(二) 垃圾收集器
SQL Server Installation Tutorial
Common exception analysis of Redis client
MySQL 数据类型及占用空间
MySQL - Function and Constraint Commands
MySQL 5.7 安装教程(全步骤、保姆级教程)
"MySQL Advanced Chapter" four, the storage structure of the index
protobuf coding and network communication applications (1)
MySQL 5.7 installation tutorial (all steps, nanny tutorials)
十二、Kotlin进阶学习:一、Lambda 表达式;二、高阶函数;
MySQL window function
Briefly describe SSRF