kyters / jlibs

Automatically exported from code.google.com/p/jlibs
1 stars 0 forks source link

Attribute namespace generation brocken for multip #51

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the provided example eclipse project to generate an xml
2. Validate xml against provided xsd 

What is the expected output? What do you see instead?
Generated output:
...
<!--(ns:btype1 , ns:ctype1?)-->
<ns1:bInstance xmlns:ns1="http://example.com/a" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ns="http://example.com/b">
    <ns:btype1 ns:bType1Attribute="1043687795">
        <ns:bType1Element1>-238173577</ns:bType1Element1>
        <ns:bType1Element2>YmFzZTY0YmluYXJ5</ns:bType1Element2>
    </ns:btype1>
    <ns:ctype1 ns2:bType1Attribute="1939310460">
        <ns2:btype1 xmlns:ns2="http://example.com/c">-634379650</ns2:btype1>
    </ns:ctype1>
</ns1:bInstance>
...
expected output:
<!--(ns:btype1 , ns:ctype1?)-->
<ns:bInstance xmlns:ns="http://example.com/a" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ns1:btype1 xmlns:ns1="http://example.com/b" ns1:bType1Attribute="-1830355942">
        <ns1:bType1Element1>1034243340</ns1:bType1Element1>
        <ns1:bType1Element2>YmFzZTY0YmluYXJ5</ns1:bType1Element2>
    </ns1:btype1>
    <ns1:ctype1 xmlns:ns1="http://example.com/b" xmlns:ns2="http://example.com/c" ns2:bType1Attribute="-508443949">
        <ns2:btype1>1038987628</ns2:btype1>
    </ns1:ctype1>
</ns:bInstance>

What version of the product are you using? On what operating system?
Linux Ubuntu 13.10

Please provide any additional information below.
If there is is more complex xsd with more than one include (at least 2 chained 
includes) then the attribute namespace might differ the element namespace.

The Class XSContentModel uses the toString Method to print the 
a comment for the used xsd model.
The Method is using an reference of MyNamespaceSupport which will then be 
populated with namespace information in the root (0) context. Since the context 
was already declared the additional namespace are missing in the certain scope. 

This cause later an issue when writing the namespaces for elements with 
attributes within an different namespace because the namespace exists already 
in the root context and does not get declared for an attribute.

I added an example and a simple patch to fix that behavior.
The XSContentModel doesn't need the MyNamespaceSupport reference at all since 
it will process the whole xsd itself and populate all required information 
correctly.

Furthermore i noticed some inconsistency in the stack generation for the 
namespace context.
Before i found the real issue which is described above i changed the behavior 
when to generate a new context (Push / Pop). But since the original version 
with just one small fix solved my problem as well i did not put this change in 
my patch.
But normally if you put a breakpoint at the end of Document generation the 
Stack for the MyNamespaceSupport object it shouldn't be 5. The Context pointer 
is correct but there are to many push operations made i think.

Original issue reported on code.google.com by Gerd.Wit...@gmail.com on 31 Mar 2014 at 11:28

Attachments:

GoogleCodeExporter commented 9 years ago
FIXED in r1788

as you suggested in patch, the bug lies in XSContentModel class.

if you change option showContentModel to false, then xml generated correctly

the fix you suggested works for your example, but fails to other scenarios

Fixing this issue, i noticed that the schema you given uses xs:base64Binary.
currently XSInstance doesn't generate correct sample values for base64Binary. 
But I will take up this as another task

the fix is uploaded to snapshots repository: 
http://dl.dropbox.com/u/326301/snapshots

Original comment by santhosh.tekuri@gmail.com on 31 Mar 2014 at 1:05