JAXB XML Marshalling Object Only, but Unmarshalling Requires Full Structure? -



JAXB XML Marshalling Object Only, but Unmarshalling Requires Full Structure? -

i using standard jaxb api work xml. need marshal , un-marshal object (so result should same object). first marshal string, , opposite -- unmarshal string object.

the problem marshaller.marshal(obj,os) giving me child only (enclosed in xml). when seek unmarshal back, errors missing parent tags expected.

e.g. (1) marshalled string object "fieldset":

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <field1>field1</field1> <field2>field2</field2>

(2) effort unmarshal xml string "fieldset" object:

javax.xml.bind.unmarshalexception: tag name "field1" not allowed. possible tag names are: - linked exception: [com.sun.msv.verifier.validityviolation: tag name "field1" not allowed. possible tag names are: "parent"]

in schema, "parent" top-level element should precede "fieldset".

why these standard jaxb operations not symmetrical, , need synchronize them , avoid child-only/missing parent issue? thanks.

to supply root element info can 1 of following:

1 - annotate class annotating @xmlrootelement

@xmlrootelement public class fieldset { }

2 - wrap object marshalling instance of jaxbelement

qname qname = new qname("root"); jaxbelement<fieldset> jaxbelement = new jaxbelement<fieldset>(qname, fieldset.class, fieldset);

xml jaxb marshalling

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -