title: Adding information to the namespace of XML generated by the JAXB marshaller
body: <p>I am using JAXB to marshal an object, which produces the following output</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;&lt;Jetstream xmlns="http://Jetstream.TersoSolutions.com/v1.0/HeartbeatEvent"&gt;......
  </code></pre>
  
  <p>My desired output is</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;&lt;Jetstream xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://Jetstream.TersoSolutions.com/v1.0/HeartbeatEvent"&gt;  
  </code></pre>
  
  <p>I am marshaling the object using the following code</p>
  
  <pre><code>    JAXBContext context;
  
      try {
          context = JAXBContext.newInstance(heartbeat.getClass());
          OutputStream writer = new ByteArrayOutputStream();
          Marshaller marshaller = context.createMarshaller();
          marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
          marshaller.setProperty("com.sun.xml.bind.xmlHeaders", "&lt;?xml version=\"1.0\"?&gt;");
  
  
          heartbeat.setHeader(header);
          heartbeat.setHeartbeatEvent(event);
  
          marshaller.marshal(heartbeat, writer);
          String stringXML = writer.toString();
          return stringXML;
  
      } catch (JAXBException e) {
          throw new RuntimeException("Problems generating XML in specified "
                  + "encoding, underlying problem is " + e.getMessage(),
                  e);
  </code></pre>
  
  <p>Adding </p>
  
  <pre><code>marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.w3.org/2001/XMLSchema"); 
  </code></pre>
  
  <p>will cause output to be close to expected, except in the wrong order and with the wrong prefix</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;&lt;Jetstream xmlns="http://Jetstream.TersoSolutions.com/v1.0/HeartbeatEvent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema"&gt;...
  </code></pre>
  
  <p>I would like to ask for some assistance with generating my namespace in the proper order and with the correct prefixes. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After following the advice in the comment I still haven't had any luck. I added the following to my package-info.java file in the relevant package. </p>
  
  <pre><code>@javax.xml.bind.annotation.XmlSchema(
      namespace = "http://Jetstream.TersoSolutions.com/v1.0/HeartbeatEvent",
      elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
      xmlns={@XmlNs(prefix="xsd", namespaceURI="http://www.w3.org/2001/XMLSchema") })
  </code></pre>
  
  <p>and my resulting output is  </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;&lt;ns2:Jetstream xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://Jetstream.TersoSolutions.com/v1.0/HeartbeatEvent"&gt;
  </code></pre>
  
  <p>for some reason the prefix was cut short, and now there are ns2: tags throughout the xml. These tags cannot be present. </p>