Re: Wrong namespace prefix in generated documents?
Michael Bishop <[email protected]> Sat, 2 Aug 2014 15:04:22 -0400
| Newsgroups | gmane.text.xml.xmlbeans.user |
|---|---|
| Message-ID | <CAAenQJdruitF5uE7a+KzPk+8JcsVQMj4xKtq3Y=j8NgyrGPCag@mail.gmail.com> |
--bcaec51d2a86813c8a04ffaa2c8d
Content-Type: text/plain; charset=UTF-8
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 <[email protected]>
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: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--bcaec51d2a86813c8a04ffaa2c8d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div><div><div><div><div><div><div><div>OK, thanks fo=
r 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.<br>
<br></div>Here's the full schema definitions:<br><br>Old:<br><xs:sch=
ema xmlns:xs=3D"<a href=3D"http://www.w3.org/2001/XMLSchema">http://ww=
w.w3.org/2001/XMLSchema</a>"<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 <b>xmlns:xxx=3D"http://..."</b><br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 targetNamespac=
e=3D"http://..."<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 elementFormDefault=3D"qualified"><br><br></div=
>New:<br><xs:schema xmlns:xs=3D"<a href=3D"http://www.w3.org/2001/X=
MLSchema">http://www.w3.org/2001/XMLSchema</a>"<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <b>xmlns:xxx=
=3D"yyy:aaa:bbb..."</b><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 targetNamespace=3D"yyy:..."<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 elementFormDefault=3D&q=
uot;qualified"><br><br></div>As you can see, in both schemas, I'=
;m declaring a namespace of <b>xxx</b>, but it's only honored in the ol=
d schema. The only thing that's changed between schemas is the namespac=
e. I had a request from our customer to change it. However, a call to:<br>
<br></div>MyGeneratedClass.Factory.newInstance() results in a document that=
looks like this:<br><br><yyy:root xmlns:yyy=3D"yyy:aaa:bbb..."=
;/><br><br></div>Applying a namespace map to an XmlOptions object doesn&=
#39;t seem to have any effect. I've tried it with the call to MyGenerat=
edClass.Factory.newInstance() and a call to MyGeneratedInstance.xmlText():<=
br>
<br></div><div>XmlOptions options =3D new XmlOptions();<br>Map<String, S=
tring> nsMap =3D new HashMap<>();<br></div><div>nsMap.put("yy=
y:aaa:bbb", "xxx");<br></div><div>options.setSaveSuggestedPr=
efixes(nsMap);<br>
<br></div><div>// No change to output.<br></div><div>MyGeneratedClass.Facto=
ry.newInstance(options);<br></div><div>MyGeneratedInstance.xmlText(options)=
;<br></div><div><br></div>I guess I have two questions:<br><br></div>1. Why=
is the prefix declaration in my schema being ignored? <b>xmlns:xxx</b> has=
never changed. It's only the value of the namespace that has changed.<=
br>
<br></div>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 &q=
uot;wrong" or I have a setting in XMLBeans misconfigured. It's bec=
oming more than just an annoying problem. XPath statements are now broken s=
ince they employ the <b>xxx</b> prefix. I'm not sure where to start tra=
cking down the issue. Both the guidance and the docs seem straightforward t=
o me, yet I can't get it to work properly.<br>
<br></div><div>Any guidance is appreciated. I'm on XMLBeans 2.5.0. If t=
here's anything more I can provide, I can do so.<br></div><div><br></di=
v>Michael Bishop<br></div><div class=3D"gmail_extra"><br><br><div class=3D"=
gmail_quote">
On Fri, Aug 1, 2014 at 12:10 PM, Cezar Andrei <span dir=3D"ltr"><<a href=
=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
om</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If you don't provide a prefix, XmlBeans will automatically pick a prefi=
x, and it tries to pick one that is part of the URI.<br>
<br>
Cezar<div class=3D""><br>
<br>
<br>
On 07/28/2014 01:27 PM, Michael Bishop wrote:<br>
</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div class=3D"">
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.<br>
<br>
Old namespace was:<br>
<br></div>
xmlns:*xxx*=3D"<a href=3D"http://ccc.bbb.aaa" target=3D"_blank">http:/=
/ccc.bbb.<u></u>aaa</a>"<br>
<br>
New namespace is:<br>
<br>
xmlns:*xxx*=3D"*yyy*:aaa:bbb:<u></u>ccc"<br>
<br>
With the old namespace, the prefix for elements was xxx. Now with the new n=
amespace, the prefix fpr elements is *yyy*. It seems switching from URL for=
m 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 pars=
e properly.<br>
<br>
It's not a big deal since the namespace is intact and things work as th=
ey should, but I can't figure out why this is happening. I don't de=
clare xmlns:*yyy* anywhere in the schema or xsdconfig files.<br>
<br>
Michael Bishop<br>
</blockquote>
<br>
<br>
------------------------------<u></u>------------------------------<u></u>-=
--------<br>
To unsubscribe, e-mail: <a href=3D"mailto:[email protected].=
org" target=3D"_blank">user-unsubscribe@xmlbeans.<u></u>apache.org</a><br>
For additional commands, e-mail: <a href=3D"mailto:[email protected]=
e.org" target=3D"_blank">[email protected]</a><br>
<br>
</blockquote></div><br></div>
--bcaec51d2a86813c8a04ffaa2c8d--