title: XSD to Java, specify to use a Java HashMap
body: <p>I am trying to generate some Java class from XSD schema. I know exactly what I want to generate in Java, and I'm trying to write the corresponding XSD schema.</p>
  
  <p>I need to represent a java.util.HashMap (HashMap). 
  I can't find how to specify in the XSD schema (or xjb binding file) that I want an HasMap in Java. It always generate a List..</p>
  
  <p>here the code I want to generate</p>
  
  <pre><code>    @XmlAccessorType(XmlAccessType.FIELD)
      @XmlType(name = "ErrorMessage", propOrder = { "name", "details"})
      public class ErrorMessage {
          @XmlElement(required = true)
          protected String name;
          @XmlElement(required = false)
          protected java.util.Map&lt;String, String&gt; details = new HashMap&lt;String, String&gt;();
  </code></pre>
  
  <p>I have tried this:</p>
  
  <pre><code>    &lt;xsd:complexType name="ErrorMessage"&gt;
      &lt;xsd:sequence&gt;
          &lt;xsd:element name="name" type="xsd:string" /&gt;
          &lt;xsd:element name="details" type="map" /&gt;
      &lt;/xsd:sequence&gt;
  &lt;/xsd:complexType&gt;
  
  
  &lt;xsd:complexType name="map"&gt;
      &lt;xsd:sequence&gt;
          &lt;xsd:element name="mapEntry" type="mapEntry" minOccurs="0" maxOccurs="unbounded" /&gt;
      &lt;/xsd:sequence&gt;
  &lt;/xsd:complexType&gt;
  
  &lt;xsd:complexType name="mapEntry"&gt;
      &lt;xsd:sequence&gt;
          &lt;xsd:element name="key" type="xsd:string" /&gt;
          &lt;xsd:element name="value" type="xsd:string" /&gt;
      &lt;/xsd:sequence&gt;
  &lt;/xsd:complexType&gt;
  </code></pre>
  
  <p>But it still continue to generate a java.util.List of mapEntry:</p>
  
  <p>In my "Error" class:
       protected Map details = new Map();</p>
  
  <p>Instead of </p>
  
  <pre><code>protected java.util.Map&lt;String, String&gt; details = new HashMap&lt;String, String&gt;();
  </code></pre>
  
  <p>And the generated "map" class is :</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "map", propOrder = {"mapEntry"})
  public class Map {
       protected List&lt;MapEntry&gt; mapEntry;
  </code></pre>
  
  <p>I really need to use a map for my application.
  Any idea about how I can do ?</p>
  
  <p>Note: I have also tried to use <a href="http://otndnld.oracle.co.jp/document/products/as10g/101300/B25221_03/web.1013/b25603/apptypemapping.htm" rel="nofollow">Oracle owi:hasmp</a> but got a namespace error.</p>
  
  <pre><code>xmlns:owi="http://www.oracle.com/webservices/internal" (also tried with xmlns:owi="http://www.oracle.com/webservices/internal/literal")
  </code></pre>
  
  <p>included in my schema declaration</p>
  
  <p>and my "details" element declared as below</p>
  
  <pre><code>&lt;xsd:element name="details" type="owi:hashmap" /&gt;
  </code></pre>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>src-resolve.4.2: Error resolving component 'owi:hasmap'. It was
    detected that 'owi:hasmap' is in namespace<br>
    '<a href="http://www.oracle.com/webservices/internal" rel="nofollow">http://www.oracle.com/webservices/internal</a>', but components from this
    namespace are not referenceable from   schema document
    'file://myFile.xsd. If this is the incorrect namespace, perhaps the
    prefix of 'owi:hasmap' needs to be   changed. If this is the correct
    namespace, then an appropriate 'import' tag should be added to
    'file://myFile.xsd</p>
  </blockquote>
  
  <p>And it can not associate "owi:hasmap" to any type definition component.</p>
  
  <p>Any idea ?</p>