XmlBeans has to store and preserve the prefixes wherever possible, because this is the only way to preserve the qname values inside a document that has an unknown schema. Don't forget that uris and prefixes have meanings outside of element and attribute names, but also inside attribute values and text.
Cezar -----Original Message----- From: Muzaffer Ozakca [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 13, 2007 3:16 PM To: user@xmlbeans.apache.org Subject: Re: Forcing namespace prefixes After a couple hours of struggling, here are my conclusions: Jacob Danner wrote: > Hi Muzaffer, > You might be able to do something with XmlCursor > (prefixForNamespace(...) )to add the prefix and then use the XmlOption > (setSave ... ) to get this behavior. This is what I used: # ModsType mods = modsDoc.addNewMods(); # XmlCursor cursor = mods.newCursor(); # cursor.toFirstContentToken(); # cursor.insertNamespace("mods", "http://www.loc.gov/mods/v3"); This actually adds the output XML by adding prefixes but it doesn't change the actual node names by adding a prefix. So, you can get XMLBeans to save/print it with the namespace prefixes but if you do getDomNode(), the node(s) you have will still have their names without a prefix. XMLBeans should be saving the prefix somewhere other than within each node and use it when saving. I also noticed that you can have the same effect without using Cursor by doing # mods.getDomNode().setPrefix("mods") although it fails at some point if you try to modify the document. For now, I'll save the output of XMLBeans and read it back some other way. Thanks anyways. > > I must ask though, why you need a specific prefix if you are working > with DOM implementations. Requiring a specific prefix will lead to > LOTS of maintenance issues. > > Hope this helps, > -Jacob Danner > > On 6/12/07, Muzaffer Ozakca <[EMAIL PROTECTED]> wrote: >> Hi all, >> >> I'm using XMLBeans to create a document. Then I'm importing the >> generated document into another DOM tree using the DOM API (by calling >> getType.getDomMode() first to get the dom node from the XMLBeans >> generated document and then calling importNode()) >> >> This is working. I'm now trying to force namespace prefixes on all >> nodes. In other words, instead of: >> <a> >> <b/> >> <c/> >> </a> >> >> I want: >> <t:a> >> <t:b/> >> <t:c/> >> </t:a> >> >> where t is the namespace prefix. Is there a way to enable that? I played >> with a few settings in XmlOptions but none worked so far. >> >> I'm pretty new to XML processing with Java, I am hoping XMLBeans is >> going to make it easier. >> >> Thanks. >> >> m >> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]