-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlTest.java
More file actions
55 lines (45 loc) · 1.39 KB
/
Copy pathXmlTest.java
File metadata and controls
55 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import org.dom4j.DocumentException;
import org.junit.Test;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.xml.bind.annotation.XmlRootElement;
import cn.mrdear.util.xml.XmlUtil;
/**
* @author Niu Li
* @date 2016/12/11
*/
public class XmlTest
{
@Test
public void testXmlReder() throws DocumentException {
InputStream stream = XmlTest.class.getResourceAsStream("message.xml");
String result = XmlUtil.reader(new InputStreamReader(stream),"content","gift");
System.out.println(result);
}
@Test
public void testBeanToXml() {
User user = new User();
user.setUsername("zhangsan");
user.setPassword("123456");
System.out.println(XmlUtil.beanToXml(user));
//<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xml><password>123456</password><username>zhangsan</username></xml>
//需要手动去除前面头部
}
@XmlRootElement(name = "xml")
static class User{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
}