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]