xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cezar Andrei <cezar.and...@oracle.com>
Subject Re: Wrong namespace prefix in generated documents?
Date Mon, 04 Aug 2014 20:31:06 GMT
Michael,

That's odd, please check that your namespace URI is exactly the same in 
both the schema and the map you're setting. Also, make sure the prefix 
you want is not already used in your document with a different URI.

If it's still not working and you're not afraid of debugging, you can 
trace the ensureMapping method in Saver.java:757 .
http://svn.apache.org/viewvc/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Saver.java?view=markup

Cezar

On 08/02/2014 02:04 PM, Michael Bishop wrote:
> OK, thanks for the information. Unfortunately, this doesn't seem to 
> fix the problem. I thought I'd tried the steps outlined in the linked 
> blog before, but I did it again, just in case.
>
> Here's the full schema definitions:
>
> Old:
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> *xmlns:xxx="http://..."*
>            targetNamespace="http://..."
>            elementFormDefault="qualified">
>
> New:
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> *xmlns:xxx="yyy:aaa:bbb..."*
>            targetNamespace="yyy:..."
>            elementFormDefault="qualified">
>
> As you can see, in both schemas, I'm declaring a namespace of *xxx*, 
> but it's only honored in the old schema. The only thing that's changed 
> between schemas is the namespace. I had a request from our customer to 
> change it. However, a call to:
>
> MyGeneratedClass.Factory.newInstance() results in a document that 
> looks like this:
>
> <yyy:root xmlns:yyy="yyy:aaa:bbb..."/>
>
> Applying a namespace map to an XmlOptions object doesn't seem to have 
> any effect. I've tried it with the call to 
> MyGeneratedClass.Factory.newInstance() and a call to 
> MyGeneratedInstance.xmlText():
>
> XmlOptions options = new XmlOptions();
> Map<String, String> nsMap = new HashMap<>();
> nsMap.put("yyy:aaa:bbb", "xxx");
> options.setSaveSuggestedPrefixes(nsMap);
>
> // No change to output.
> MyGeneratedClass.Factory.newInstance(options);
> MyGeneratedInstance.xmlText(options);
>
> I guess I have two questions:
>
> 1. Why is the prefix declaration in my schema being ignored? 
> *xmlns:xxx* has never changed. It's only the value of the namespace 
> that has changed.
>
> 2. I find it odd that Map has no effect either. Is there anything else 
> I should be looking into? I'm not sure if my schema is somehow "wrong" 
> or I have a setting in XMLBeans misconfigured. It's becoming more than 
> just an annoying problem. XPath statements are now broken since they 
> employ the *xxx* prefix. I'm not sure where to start tracking down the 
> issue. Both the guidance and the docs seem straightforward to me, yet 
> I can't get it to work properly.
>
> Any guidance is appreciated. I'm on XMLBeans 2.5.0. If there's 
> anything more I can provide, I can do so.
>
> Michael Bishop
>
>
> On Fri, Aug 1, 2014 at 12:10 PM, Cezar Andrei <cezar.andrei@oracle.com 
> <mailto:cezar.andrei@oracle.com>> wrote:
>
>     If you don't provide a prefix, XmlBeans will automatically pick a
>     prefix, and it tries to pick one that is part of the URI.
>
>     Cezar
>
>
>
>     On 07/28/2014 01:27 PM, Michael Bishop wrote:
>
>         Hello all. I've recently changed the namespace of my schema.
>         Now I'm getting the wrong prefix name and I'm not sure why.
>
>         Old namespace was:
>
>         xmlns:*xxx*="http://ccc.bbb.aaa"
>
>         New namespace is:
>
>         xmlns:*xxx*="*yyy*:aaa:bbb:ccc"
>
>         With the old namespace, the prefix for elements was xxx. Now
>         with the new namespace, the prefix fpr elements is *yyy*. It
>         seems switching from URL form to URI form has caused the
>         processor to start using the first part of the URI as the
>         prefix? This happens when I call the static
>         Factory.newInstance() on generated classes. Older documents
>         with the correct prefix still parse properly.
>
>         It's not a big deal since the namespace is intact and things
>         work as they should, but I can't figure out why this is
>         happening. I don't declare xmlns:*yyy* anywhere in the schema
>         or xsdconfig files.
>
>         Michael Bishop
>
>
>
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>     <mailto:user-unsubscribe@xmlbeans.apache.org>
>     For additional commands, e-mail: user-help@xmlbeans.apache.org
>     <mailto:user-help@xmlbeans.apache.org>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Mime
View raw message