Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 176416 - XML Generation not picking up all available namespaces
Summary: XML Generation not picking up all available namespaces
Status: CLOSED DUPLICATE of bug 105128
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: 1.5.3   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Gabriel Indik CLA
QA Contact: David Williams CLA
URL:
Whiteboard: DC - Created Proposed patch
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-05 16:00 EST by David Carver CLA
Modified: 2007-04-03 11:52 EDT (History)
1 user (show)

See Also:


Attachments
Schemas that can be used to reproduce problem (484.42 KB, application/x-zip)
2007-03-05 16:04 EST, David Carver CLA
no flags Details
Code to get all xmlns that are defined in an XML document (1.43 KB, text/plain)
2007-03-08 15:17 EST, David Carver CLA
no flags Details
Allow Namespaces to always be deleteable. (1.12 KB, text/plain)
2007-03-08 16:21 EST, David Carver CLA
no flags Details
Patch for XSDImpl, should be applied to 2.x as well. (167.44 KB, patch)
2007-03-08 16:22 EST, David Carver CLA
no flags Details | Diff
Reformatted patch, and cleaned up code. (3.02 KB, patch)
2007-03-08 21:57 EST, David Carver CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Carver CLA 2007-03-05 16:00:21 EST
Build ID: 3.2.2

Steps To Reproduce:
1. Create a New XML File based on an XSD that contains more than one namespace for the output xml instance
2. Only the first namespace is identified, all others have to be manually added.

Web Tools 1.5.2 picked up the extra namespaces.


More information:
If an XML Instance is generated from a XML Schema that contains additional schema definitions from multiple namespaces for the output document, these are not showing up in the available namespace area.  Only the first one is showing up.
Comment 1 David Carver CLA 2007-03-05 16:04:55 EST
Created attachment 60283 [details]
Schemas that can be used to reproduce problem

Added sample schemas.   Generate from the STAR/Rev/BODs/Developer version.

Also, when the namespace extra namespace is added, exraneous items are being added to the SchemaLocation, only the primary namespace should be added to the schemalocation.
Comment 2 David Carver CLA 2007-03-06 20:50:42 EST
This appears to happen when there are no Imports included in the XSD.  However, the way the developer versions of the schema are constructed, this probably needs to look farther in to make sure there are no xsd:import statements in any of the included schemas to make sure it retrieves all possible namespaces.

To see this in action, generate a XML that produces the expected namespaces, generate an instance using the Meta.xsd file in the STAR/Rev/Common/Components directory.  This will populate 6 more namespaces due to the import statements appearing in this XSD.
Comment 3 Valentin Baciu CLA 2007-03-07 17:43:48 EST
Gabriel, I believe you were looking at this functionality recently.
Comment 4 David Carver CLA 2007-03-08 09:23:29 EST
I dug a bit further into the code and found in XSDImpl when it loads the resources a ResourceSet of all additional resources is created as well.  However, the way the classes and code are currently constructed there is no simple way to get to the additional resources in the original set, because all the functionallity just works off the theXSDSchema.   The getNamespaces method does not know or has access to the original ResourceSet that was loaded when the root schema was loaded.

Use of the XSDSearchQueryTool util from the XSD library to find the additional includes seems to go into a recursive call loop as it's not detecting possible recursions that can happen with the xsd:include/imports.

I checked, and this same issue currently exists in the HEAD code, as well as in the 1.5.x branch.  The issue also existed in the 1.5.2 branch, I just didn't notice it until the 1.5.3 branch.

Comment 5 David Carver CLA 2007-03-08 15:17:04 EST
Created attachment 60443 [details]
Code to get all xmlns that are defined in an XML document

The above code will retrieve the namespaces, but not the location.  This needs to be added manually.   In the getProperty() method in the XSDImpl, the following line would need to be added after the getImportedNamespaceInfo() method call (line 834).

getAllNamespacesInfo(xsdSchema, list);

This allows for the checking of the current XSDImport namespaces, and then getting any extra namespaces through the new method.  The new method will not add a namespace if it has already been defined.

Only issue is that you can't delete the namespaces added through XSDImport or this new method, and you should be able to because not all namespaces are used in the instance, just by the XSD.
Comment 6 David Carver CLA 2007-03-08 16:21:06 EST
Created attachment 60445 [details]
Allow Namespaces to always be deleteable.
Comment 7 David Carver CLA 2007-03-08 16:22:10 EST
Created attachment 60446 [details]
Patch for XSDImpl, should be applied to 2.x as well.

Patch for XSDImpl to handle importing xmlns specified namespaces.
Comment 8 Gabriel Indik CLA 2007-03-08 18:25:07 EST
Dave,
Thanks a lot for reporting the bug and for the proposed code and patch. This problem was actually detected in earlier tests and a patch for it has been under development. I wanted to take a look at yours but it seems there might have been code formatting applied to it making it hard to see the changes introduced. If you can, please re-submit the patch without the formatting change.
Comment 9 David Carver CLA 2007-03-08 21:57:05 EST
Created attachment 60460 [details]
Reformatted patch, and cleaned up code.

Cleaned up and reformatted patch.
Comment 10 Gabriel Indik CLA 2007-03-13 19:29:43 EDT
Dave,
Thanks a lot for reformatting the patch. I went over it and noted you are collecting the namespaces throughout the top level schema contents. While this can help find more namespaces, it might not be enough to guarantee that the list of namespaces obtained is complete. This is because other required namespaces could be located in schemas being imported in other imported schemas, or in schemas imported in included schemas (or any combination of these). In order to ensure that all required namespaces have been collected it would be necessary to recursively explore all imports/includes. I recently posted a patch for this in bug 105128. If you can please give it a try to see if it correctly solves the problem.


*** This bug has been marked as a duplicate of bug 105128 ***
Comment 11 David Carver CLA 2007-03-13 21:06:04 EDT
Yep, I realized this.  Too me the best solution is the query and get the available imported schemas from the RecordSet that is created when the resource is loaded, but this currently would require some refactoring of the existing code, as this is lost once the resource is loaded.  Unfortunately because this is not kept, it requires an addtional navigation step through the XSD model to get the imports, which isn't really necessary.

Long term I would look at refactoring the XSDImpl to keep the recordset around and make it avaiable for getting these namespaces, or extract these namespaces and make them available for later processing.  The resource.load will already handle the duplicate and circular includes/imports that could occur, so you are only left with the schemas and namespaces that are used.

Comment 12 John Lanuti CLA 2007-04-03 11:52:57 EDT
Closing as part of mass query to clean up old resolved bugs in untargetted milestones.