xsd - Generating closing tag for empty elements using XMLBeans -



xsd - Generating closing tag for empty elements using XMLBeans -

i have next xsd :

<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeformdefault="unqualified" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="employee" type="employeetype"/> <xs:complextype name="employeetype"> <xs:sequence> <xs:element type="xs:string" name="name"/> <xs:element type="xs:int" name="age"/> <xs:element type="xs:string" name="address"/> </xs:sequence> </xs:complextype> </xs:schema>

if set value only name i.e

employeedocument request=employeedocument.factory.newinstance(); employeetype emp=employeetype.factory.newinstance(); emp.setname("name"); request.setemployee(emp);

then xmlbeans generating next xml:

<employee> <name>name</name> </employee>

but need next kind of xml generated ,means closing tags </> elements values not set in programme :

<employee> <name>name</name> <age/> <address/> </employee>

well , xmlbeans generating <address/> if set empty string i.e emp.setaddress("");

is there way meet such requirement using xmlbeans , without setting empty string.

and more on not set empty string element age of type int .

any help appreciated.

the xmlschema way add together nillable="true" age , address elements. when recompile xsd xmlbeans, have .setnilage() , .setniladdress() methods. generated xml like:

<employee xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <name>name</name> <age xsi:nil="true"/> <address xsi:nil="true"/> </employee>

by way, improve build document using .addnewemployee() instead of .setemployee() if possible. avoids copying employee instance document more expensive.

xsd marshalling unmarshalling xmlbeans

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -