How do I name a list of Complex Types in XSD?

WalkingDown

New Member
I am trying to create an XSD to represent my domain objects, then generate the Java objects using JAXB. I also have XML files which are unmarshalled into the Java classes at runtime.My object model is very simple right now, I have a Script object which contains a list of HttpRequest objects.Here is my XSD:\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="script" type="script"/><xs:complexType name="getRequest"> <xs:attribute name="url" type="xs:string"/></xs:complexType><xs:complexType name="script"> <xs:sequence> <xs:element name="httpRequests" type="getRequest" minOccurs="1" maxOccurs="unbounded"/> </xs:sequence></xs:complexType></xs:schema>\[/code\]This results in the Java model I would like:\[code\] for (GetRequest request: script.getHttpRequests() ) { String url = request.getUrl(); log.info("URL [ "+url+" ]"); }\[/code\]However, my XML structure must look like this to match the XSD:\[code\]<?xml version="1.0" encoding="UTF-8"?><script> <httpRequests url="http://www.google.com"/> <httpRequests url="http://www.yahoo.com"/></script>\[/code\]Is there any way that I can restructure my XSD such that my XML looks more intuitive, yet I still get the same Java object model? My last resort appears to be writing a custom JAXB binding, but this seems like such a basic problem that I am surprised there isn't a better solution. I would like my XML to look something like this:\[code\]<?xml version="1.0" encoding="UTF-8"?><script> <httpRequests> <getRequest url="http://www.google.com"/> <getRequest url="http://www.yahoo.com"/> </httpRequests></script>\[/code\]
 
Back
Top