java - JAXB: How to avoid repeated namespace definition for xmlns:xsi -


I have a JAXB setup, where I change the object type Person with the object Using an @ XmlJavaTypeAdapter, type is the only UUD of that person in type PersonRef . Although it works perfectly well, however, the generated XML uses the same name space ( xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" / Code>), although it is usually okay, it does not look right.

How can I configure JAXB to declare xmlns: xs in the initial time of the document? Can I manually add namespace announcements to the original element?

Here is an example that I would like to receive:

Current:

  & lt; Person uuid = "6ec0cf24-e880-431b-ada0-a5835e2a565a" & gt; & Lt; Relationship type = "child" & gt; & Lt; To xsi: type = "personRef" uuid = "56a930c0-549 9-467f-8263-c2a9f9ecc5a0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema -instance" /> & Lt; / Relation & gt; & Lt; Relationship type = "child" & gt; & Lt; To xsi: type = "personRef" uuid = "6ec0cf24-e880-431b-ada0-a5835e2a565a" xmlns: xsi = "http://www.w3.org/2001/XMLSchema -instance" /> & Lt; / Relation & gt; & Lt ;! - SNIP: Some more links - & gt; & Lt; / Person & gt;   

Wanted:

  & lt; Person uuid = "6ec0cf24-e880-431b-ada0-a5835e2a565a" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"> & Lt; Relationship type = "child" & gt; & Lt; To xsi: type = "personRef" uuid = "56a930c0-549 9-467f-8263-c2a9f9ecc5a0" /> & Lt; / Relation & gt; & Lt; Relationship type = "child" & gt; & Lt; To xsi: type = "personRef" uuid = "6ec0cf24-e880-431b-ada0-a5835e2a565a" /> & Lt; / Relation & gt; & Lt ;! - SNIP: Some more links - & gt; & Lt; / Person & gt;    

You can do it with code:

 < Code> Marshaller.setProperty ("com.sun.xml.bind.namespacePrefixMapper", new namespacefixesmapper () {@Override public string} getPreDeclaredNamespaceUris () {return new string} {overlapping public string getPreferredPrefix} (XML) NamespaceURI, string suggestion, boolean is requiredfirfix) {if (namespaceURI.exe (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI)) return "xsi"; if (name Pesyuri.akwayls (XMLConstants.W3C_XML_SCHEMA_NS_URI)) "xs" return to; if (Namsthankuara. XML_MIME_URI)) "xmime"; Return suggestion;}});    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -