Re: Wrong namespace prefix in generated documents?
Michael Bishop <[email protected]> Thu, 7 Aug 2014 13:22:25 -0400
| Newsgroups | gmane.text.xml.xmlbeans.user |
|---|---|
| Message-ID | <CAAenQJdDR2h9fA4dKN1i44V2Qxeckozke2iybQH-iQnnUJfwpg@mail.gmail.com> |
--047d7ba97002132f6105000d551f
Content-Type: text/plain; charset=UTF-8
I've got to figure out how to debug it. Currently, it's in a Maven project
with the XMLBeans plugin running the schema compilation.
The map works when I call save(options) or xmlText(options), but not when
the document is created (Factory.newInstance(options)).
// Option that sets the namespace map.
XmlOptions options = ...;
MyDoc doc = MyDoc.Factory.newInstance(options);
System.out.println("Wrong prefix: " + doc.xmlText());
System.out.println("Right prefix: " + doc.xmlText(options));
The schema is spread out across multiple files. I'm going to try to create
a small test case to see if I can't reproduce this.
On Mon, Aug 4, 2014 at 4:31 PM, Cezar Andrei <[email protected]>
wrote:
> 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 <[email protected]
>> <mailto:[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]
>> <mailto:[email protected]>
>>
>> For additional commands, e-mail: [email protected]
>> <mailto:[email protected]>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--047d7ba97002132f6105000d551f
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div><div><div><div>I've got to figure out how to=
debug it. Currently, it's in a Maven project with the XMLBeans plugin =
running the schema compilation.<br><br></div>The map works when I call save=
(options) or xmlText(options), but not when the document is created (Factor=
y.newInstance(options)).<br>
</div><div><br></div><div>// Option that sets the namespace map.<br></div><=
div>XmlOptions options =3D ...;<br><br></div>MyDoc doc =3D MyDoc.Factory.ne=
wInstance(options);<br><br></div>System.out.println("Wrong prefix: &qu=
ot; + doc.xmlText());<br>
</div>System.out.println("Right prefix: " + doc.xmlText(options))=
;<br><br></div>The schema is spread out across multiple files. I'm goin=
g to try to create a small test case to see if I can't reproduce this.<=
br>
</div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On Mon,=
Aug 4, 2014 at 4:31 PM, Cezar Andrei <span dir=3D"ltr"><<a href=3D"mail=
to:[email protected]" target=3D"_blank">[email protected]</a>&g=
t;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Michael,<br>
<br>
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.<br>
<br>
If it's still not working and you're not afraid of debugging, you c=
an trace the ensureMapping method in Saver.java:757 .<br>
<a href=3D"http://svn.apache.org/viewvc/xmlbeans/trunk/src/store/org/apache=
/xmlbeans/impl/store/Saver.java?view=3Dmarkup" target=3D"_blank">http://svn=
.apache.org/viewvc/<u></u>xmlbeans/trunk/src/store/org/<u></u>apache/xmlbea=
ns/impl/store/<u></u>Saver.java?view=3Dmarkup</a><br>
<br>
Cezar<div class=3D""><br>
<br>
On 08/02/2014 02:04 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"">
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.<br>
<br>
Here's the full schema definitions:<br>
<br>
Old:<br>
<xs:schema xmlns:xs=3D"<a href=3D"http://www.w3.org/2001/XMLSchema"=
target=3D"_blank">http://www.w3.org/<u></u>2001/XMLSchema</a>"<br></d=
iv>
*xmlns:xxx=3D"http://..."*<div class=3D""><br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0targetNamespace=3D"http://...=
"<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0elementFormDefault=3D"qualifi=
ed"<u></u>><br>
<br>
New:<br>
<xs:schema xmlns:xs=3D"<a href=3D"http://www.w3.org/2001/XMLSchema"=
target=3D"_blank">http://www.w3.org/<u></u>2001/XMLSchema</a>"<br></d=
iv>
*xmlns:xxx=3D"yyy:aaa:bbb..."*<div class=3D""><br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0targetNamespace=3D"yyy:...&qu=
ot;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0elementFormDefault=3D"qualifi=
ed"<u></u>><br>
<br></div>
As you can see, in both schemas, I'm declaring a namespace of *xxx*, bu=
t it's only honored in the old schema. The only thing that's change=
d between schemas is the namespace. I had a request from our customer to ch=
ange it. However, a call to:<div class=3D"">
<br>
<br>
MyGeneratedClass.Factory.<u></u>newInstance() results in a document that lo=
oks like this:<br>
<br>
<yyy:root xmlns:yyy=3D"yyy:aaa:bbb..."/><br>
<br>
Applying a namespace map to an XmlOptions object doesn't seem to have a=
ny effect. I've tried it with the call to MyGeneratedClass.Factory.<u><=
/u>newInstance() and a call to MyGeneratedInstance.xmlText():<br>
<br>
XmlOptions options =3D new XmlOptions();<br>
Map<String, String> nsMap =3D new HashMap<>();<br>
nsMap.put("yyy:aaa:bbb", "xxx");<br>
options.<u></u>setSaveSuggestedPrefixes(<u></u>nsMap);<br>
<br>
// No change to output.<br>
MyGeneratedClass.Factory.<u></u>newInstance(options);<br>
MyGeneratedInstance.xmlText(<u></u>options);<br>
<br>
I guess I have two questions:<br>
<br></div>
1. Why is the prefix declaration in my schema being ignored? *xmlns:xxx* ha=
s never changed. It's only the value of the namespace that has changed.=
<br>
<br>
2. I find it odd that Map has no effect either. Is there anything else I sh=
ould be looking into? I'm not sure if my schema is somehow "wrong&=
quot; 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.<div class=3D"">
<br>
<br>
Any guidance is appreciated. I'm on XMLBeans 2.5.0. If there's anyt=
hing more I can provide, I can do so.<br>
<br>
Michael Bishop<br>
<br>
<br></div><div><div class=3D"h5">
On Fri, Aug 1, 2014 at 12:10 PM, Cezar Andrei <<a href=3D"mailto:cezar.a=
[email protected]" target=3D"_blank">[email protected]</a> <mailto:=
<a href=3D"mailto:[email protected]" target=3D"_blank">cezar.andrei@o=
racle.<u></u>com</a>>> wrote:<br>
<br>
=C2=A0 =C2=A0 If you don't provide a prefix, XmlBeans will automaticall=
y pick a<br>
=C2=A0 =C2=A0 prefix, and it tries to pick one that is part of the URI.<br>
<br>
=C2=A0 =C2=A0 Cezar<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 On 07/28/2014 01:27 PM, Michael Bishop wrote:<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Hello all. I've recently changed the namesp=
ace of my schema.<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Now I'm getting the wrong prefix name and I=
'm not sure why.<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Old namespace was:<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 xmlns:*xxx*=3D"<a href=3D"http://ccc.bbb.a=
aa" target=3D"_blank">http://ccc.bbb.<u></u>aaa</a>"<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 New namespace is:<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 xmlns:*xxx*=3D"*yyy*:aaa:bbb:<u></u>ccc&qu=
ot;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 With the old namespace, the prefix for elements=
was xxx. Now<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 with the new namespace, the prefix fpr elements=
is *yyy*. It<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 seems switching from URL form to URI form has c=
aused the<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 processor to start using the first part of the =
URI as the<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 prefix? This happens when I call the static<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Factory.newInstance() on generated classes. Old=
er documents<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 with the correct prefix still parse properly.<b=
r>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 It's not a big deal since the namespace is =
intact and things<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 work as they should, but I can't figure out=
why this is<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 happening. I don't declare xmlns:*yyy* anyw=
here in the schema<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 or xsdconfig files.<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Michael Bishop<br>
<br>
<br>
<br>
=C2=A0 =C2=A0 ------------------------------<u></u>------------------------=
------<u></u>---------<br>
=C2=A0 =C2=A0 To unsubscribe, e-mail: <a href=3D"mailto:user-unsubscribe@xm=
lbeans.apache.org" target=3D"_blank">user-unsubscribe@xmlbeans.<u></u>apach=
e.org</a><br></div></div>
=C2=A0 =C2=A0 <mailto:<a href=3D"mailto:[email protected]=
.org" target=3D"_blank">user-unsubscribe@<u></u>xmlbeans.apache.org</a>>=
<div class=3D""><br>
=C2=A0 =C2=A0 For additional commands, e-mail: <a href=3D"mailto:user-help@=
xmlbeans.apache.org" target=3D"_blank">[email protected]</a><br=
></div>
=C2=A0 =C2=A0 <mailto:<a href=3D"mailto:[email protected]" t=
arget=3D"_blank">user-help@xmlbeans.<u></u>apache.org</a>><br>
<br>
<br>
</blockquote><div class=3D"HOEnZb"><div class=3D"h5">
<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>
</div></div></blockquote></div><br></div>
--047d7ba97002132f6105000d551f--