You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Adam Pelletier <ad...@moesol.com> on 2007/10/01 21:23:28 UTC

Session.importXML() and namespaces.

I'm having trouble getting namespaces to resolve properly. 

My XML looks like:

<?xml version="1.0" encoding="UTF-8"?>
<mydoc xmlns="http://www.moesol.com" xmlns:md="http://www.moesol.com">
    <mydoc-inner key="foo" value="bar"/>
</mydoc>


My code sets up the namespace:

session.setNamespacePrefix("md", "http://www.moesol.com");
session.importXML(bvVswanCfg.absolute(), new 
FileInputStream(f_esdConfigFile), 
ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
session.save();


And my output looks like:

/bv/config/vswan/_pre2:mydoc/@jcr:primaryType = nt:unstructured
/bv/config/vswan/_pre2:mydoc/_pre2:mydoc-inner/@key = foo
/bv/config/vswan/_pre2:mydoc/_pre2:mydoc-inner/@value = bar
/bv/config/vswan/_pre2:mydoc/_pre2:mydoc-inner/@jcr:primaryType = 
nt:unstructured

I can't seem to wire the namespaces together and get "_pre2" in the 
output.  I was expecting this to be "md" and not "_pre2".

Thanks in advance.
Adam

Re: Session.importXML() and namespaces.

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 10/1/07, Adam Pelletier <ad...@moesol.com> wrote:
> I can't seem to wire the namespaces together and get "_pre2" in the
> output.  I was expecting this to be "md" and not "_pre2".

Using Session.setNamespacePrefix() only affects the current session.
You'll want to use NamespaceRegistry.registerNamespace() if you want
to globally register a specific prefix for a namespace.

The _pre2 prefix in your example is autoregistered by the XML import
code when it sees a namespace URI that hasn't been explicitly
registered in the global namespace registry.

BR,

Jukka Zitting