Note that there are some explanatory texts on larger screens.

plurals
  1. POJAXB adding namespace to parent but not to the child elements contained
    primarykey
    data
    text
    <p>I put together an XSD and used JAXB to generate classes out of it.</p> <p>Here are my XSDs-</p> <pre><code>myDoc.xsd : &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema xmlns="http://www.mydoc.org" targetNamespace="http://www.mydoc.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mtp="http://www.mytypes.com" elementFormDefault="qualified"&gt; &lt;xs:import namespace="http://www.mytypes.com" schemaLocation="mytypes.xsd" /&gt; &lt;xs:element name="myDoc"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="crap" type="xs:string"/&gt; &lt;xs:element ref="mtp:foo"/&gt; &lt;xs:element ref="mtp:bar"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; </code></pre> <p></p> <pre><code>mytypes.xsd &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema targetNamespace="http://www.mytypes.com" xmlns="http://www.mytypes.com" xmlns:tns="http://www.mytypes.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified"&gt; &lt;xs:element name="foo" type="tns:Foo"/&gt; &lt;xs:element name="bar" type="tns:Bar"/&gt; &lt;xs:element name="spam" type="tns:Spam"/&gt; &lt;xs:simpleType name="Foo"&gt; &lt;xs:restriction base="xs:string"&gt;&lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;xs:complexType name="Bar"&gt; &lt;xs:sequence&gt; &lt;xs:element ref="spam"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:simpleType name="Spam"&gt; &lt;xs:restriction base="xs:string" /&gt; &lt;/xs:simpleType&gt; &lt;/xs:schema&gt; </code></pre> <p>The document marshalled is-</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;myDoc xmlns:ns2="http://www.mytypes.com"&gt; &lt;crap&gt;real crap&lt;/crap&gt; &lt;ns2:foo&gt;bleh&lt;/ns2:foo&gt; &lt;ns2:bar&gt; &lt;spam&gt;blah&lt;/spam&gt; &lt;/ns2:bar&gt; &lt;/myDoc&gt; </code></pre> <p>Note that the <code>&lt;spam&gt;</code> element uses the default namespace. I would like it to use the <code>ns2</code> namespace. The schema (mytypes.xsd) expresses the fact that <code>&lt;spam&gt;</code> is contained within <code>&lt;bar&gt;</code> which in the XML instance is bound to the <code>ns2</code> namespace.</p> <p>I've broken my head over this for over a week and I would like <code>ns2</code> prefix to appear in <code>&lt;spam&gt;</code>. What should I do?</p> <p>Required : </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;myDoc xmlns:ns2="http://www.mytypes.com"&gt; &lt;crap&gt;real crap&lt;/crap&gt; &lt;ns2:foo&gt;bleh&lt;/ns2:foo&gt; &lt;ns2:bar&gt; &lt;ns2:spam&gt;blah&lt;/ns2:spam&gt;&lt;!--NS NS NS--&gt; &lt;/ns2:bar&gt; &lt;/myDoc&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload