I have the following scenario: using XML Data Bindings, I have an object created from schema A, and a different object created using schema B. However, schema B imports schema A in order to define children nodes of the A type.
So, right now I have:
- unit1,
objectA(from schema A) - unit2,
objectB(from schema B),objectA(from schema B which imports schema A)
The unit2.objectA class is, of course, incompatible with unit1.objectA. The definition in unit2 is also different, because it doesn’t include some namespace attributes (this is important: I think these are implicit because the parent node also have them.)
And this is my problem: I can do lots of stuff given that these are just IXMLDocument objects, but I want to be able to create unit1.objectA from unit2.objectA.
My initial thought was that one should be able to export nodes from a document, and that there should be an option to make this exported node “kosher” according to the correct schema (so, a node of type A inside a document B should export and validate against the schema A.) I understand that this may be wishing too much, so my question may be rephrased:
How can I export a node from a IXMLDocument object into a new IXMLDocument object, while adding/overriding namespace attributes (xmlns, xmlns:xsi, xsi:schemaLocation) in the exported node / document?
Turned out to be a really tricky issue. Resorted to use low level DOM functions from my XML library and a lot of elbow grease; had to export the wanted fragment, and manually adjusted schemas and namespaces, then reformatted everything.