Employee.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="1.0" elementFormDefault="qualified"> <xsd:include schemaLocation="Family.xsd"/> <xsd:element name="NewFields"> <xsd:complexType> <xsd:sequence> <xsd:element name="empFirstName" type="xsd:string" /> <xsd:element name="empLastName" type="xsd:string" /> <xsd:element name="family" type="FamilyFields" nillable="true" maxOccurs="unbounded" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
Family.xsd
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="1.0" elementFormDefault="qualified"> <xsd:complexType name="FamilyFields"> <xsd:sequence> <xsd:element name="relation" type="xsd:string" /> <xsd:element name="firstName" type="xsd:string" /> <xsd:element name="lastName" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
A third-party application using these 2 schemes generates an xml string, for example -
<NewFields> <empFirstName>Kevin</empFirstName> <empLastName>Smith</empLastName> <family> <FamilyFields> <relation>self</relation> <firstName>New Kevin</firstName> <lastName>New Smith</lastName> </FamilyFields> <FamilyFields> <relation>wife</relation> <firstName>Jennifer</firstName> <lastName>Smith</lastName> </FamilyFields> </family> </NewFields>
The second scheme is always a fixed scheme.
My requirement is to parse the relationship tag and if the relationship is "I", I need to rewrite empFirstName and empLastName with the firstName and lastName of the corresponding fields.
How can i achieve this?
EDIT 1: Employee.xsd is dynamic and can be anything. But Family.xsd is static and can be imported from any other xsd.
source share