xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Bishop <bisho...@gmail.com>
Subject Re: Wrong namespace prefix in generated documents?
Date Thu, 07 Aug 2014 17:53:35 GMT
OK, here is a test schema:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:aaa="bbb:ccc:ddd:eee:fff:aaa"
           targetNamespace="bbb:ccc:ddd:eee:fff:aaa"
           elementFormDefault="qualified">

    <xs:element name="test" type="aaa:testType"/>

    <xs:complexType name="testType">
        <xs:sequence>
            <xs:element name="name" type="xs:string" minOccurs="1"
maxOccurs="1"/>
            <xs:element name="uuid" type="xs:string" minOccurs="1"
maxOccurs="1"/>
            <xs:element name="version" type="xs:string" minOccurs="1"
maxOccurs="1"/>
            <xs:element name="created" type="xs:string" minOccurs="1"
maxOccurs="1"/>
            <xs:element name="createdBy" type="xs:string" minOccurs="1"
maxOccurs="1"/>
            <xs:element name="modified" type="xs:string" minOccurs="1"
maxOccurs="1"/>
            <xs:element name="modifiedBy" type="xs:string" minOccurs="1"
maxOccurs="1"/>
            <xs:element name="description" type="xs:string" minOccurs="0"
maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="version" type="xs:string" use="required"/>
    </xs:complexType>
</xs:schema>

TestDocument doc = TestDocument.Factory.newInstance();
doc.addNewTest();

// Wrong, default Factory output.
doc.xmlText(): <bbb:test xmlns:bbb="bbb:ccc:ddd:eee:fff:aaa"/>

// Correct output that I can't get from just the Factory.newInstance()
method.
doc.xmlText(options): <aaa:test xmlns:aaa="bbb:ccc:ddd:eee:fff:aaa"/>

Does anyone else get the same compilation results? Is there a reason the
new instances won't default to xmlns:aaa as declared? I'd be hard pressed
to believe that something in XMLBeans is causing this. It's probably
something I'm doing. Does the XSDConfig file have any influence that I'm
missing?

Michael Bishop


On Thu, Aug 7, 2014 at 1:22 PM, Michael Bishop <bishopmw@gmail.com> wrote:

> 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 <cezar.andrei@oracle.com>
> 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 <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