Skip to content

Commit 0d07b38

Browse files
committed
load a model from a string
1 parent 56da34c commit 0d07b38

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/java/org/mujoco/MuJoCoXML.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.File;
55
import java.io.FileWriter;
66
import java.io.IOException;
7+
import java.io.StringReader;
78
import java.io.StringWriter;
89

910
import javax.xml.bind.JAXBContext;
@@ -23,7 +24,14 @@ public static Mujoco unmarshal(File xml) throws JAXBException {
2324
return (Mujoco) jaxbUnmarshaller.unmarshal(xml);
2425

2526
}
27+
public static Mujoco unmarshal(String xml) throws JAXBException {
28+
JAXBContext jaxbContext = JAXBContext.newInstance(Mujoco.class);
29+
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
2630

31+
// We had written this file in marshalling example
32+
return (Mujoco) jaxbUnmarshaller.unmarshal(new StringReader(xml));
33+
34+
}
2735
public static String marshal(Mujoco source) throws JAXBException {
2836
JAXBContext jaxbContext = JAXBContext.newInstance(Mujoco.class);
2937
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

0 commit comments

Comments
 (0)