java - JAXB: How to avoid repeated namespace definition for xmlns:xsi -
I have a JAXB setup, where I change the object type 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: Wanted: You can do it with code: Person with the object Using an @ XmlJavaTypeAdapter, type is the only UUD of that person in type
xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" / Code>), although it is usually okay, it does not look right.
& 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;
& 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;
< 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
Post a Comment