Repository navigation
Expand file tree
/
Copy pathSolution.java
More file actions
42 lines (35 loc) · 1.51 KB
/
Copy pathSolution.java
File metadata and controls
42 lines (35 loc) · 1.51 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
package com.javarush.task.task33.task3308;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
/*
Создание класса по строке xml
*/
public class Solution {
public static void main(String[] args) throws JAXBException {
String xmlData =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<shop>\n" +
" <goods>\n" +
" <names>S1</names>\n" +
" <names>S2</names>\n" +
" </goods>\n" +
" <count>12</count>\n" +
" <profit>123.4</profit>\n" +
" <secretData>String1</secretData>\n" +
" <secretData>String2</secretData>\n" +
" <secretData>String3</secretData>\n" +
" <secretData>String4</secretData>\n" +
" <secretData>String5</secretData>\n" +
"</shop>";
StringReader reader = new StringReader(xmlData);
JAXBContext context = JAXBContext.newInstance(getClassName());
Unmarshaller unmarshaller = context.createUnmarshaller();
Object o = unmarshaller.unmarshal(reader);
System.out.println(o.toString());
}
public static Class getClassName() {
return Shop.class; //your class name
}
}