How to import an XML schema into "no namespace"

I have a schema here where I am trying to enable / import another schema that does not have a namespace (and this cannot be changed since it comes from another provider and will no longer validate their XML). Here is the first diagram:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:samp="http://sample/namespace" targetNamespace="http://sample/namespace" elementFormDefault="unqualified" attributeFormDefault="unqualified" xmlns:otr1="http://sample/import/namespace1" xmlns:otr2="http://sample/import/namespace2"> <xs:import namespace="http://sample/import/namespace1" schemaLocation="other1.xsd" /> <xs:import namespace="http://sample/import/namespace2" schemaLocation="other2.xsd" /> <!-- This one below is having problems, it is valid XML, and I am able to use it but I am not meeting the actual requirments I have (explained later) --> <xs:include schemaLocation=="NO_NAME_SPACE_PROBLEM.xsd"/> ... <xs:element ref="some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA"/> ... </xs:schema> 

And "NO_NAME_SPACE_SHEMA_PROBLEM.xsd", which can be changed to some extent, but it cannot have a namespace.

 <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified"> <xsd:element name="some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA" type="xsd:string" nillable="true"/> </xs:schema> 

The problem is that some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA is placed in the samp namespace. So when I try to set this to XML, it outputs <samp:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA><child-elem/></samp:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA> , which is a big problem because this XML will not be validated because it is not intended. So my goal is to simply import elements into a namespace without a namespace.

Update 1 . Sorry for the confusion, I used xs: include, not xs: import for a schema without names. Updated syntax for the question. I also use JiBX codegen to create domain objects and JiBX bindings for sorting. Therefore, it must also be compatible with JiBX.

Update 2 . According to Scuffman, now I will use xs: import. I think I will branch this out to a new question.

+4
source share
1 answer

You tried

 <xs:import namespace="" schemaLocation="NO_NAME_SPACE_PROBLEM.xsd"/> 

Interestingly, the XML Schema specification strongly suggests that

 <xs:import schemaLocation="NO_NAME_SPACE_PROBLEM.xsd"/> 

must import NO_NAME_SPACE_PROBLEM.xsd into "no namespace". If your environment imports it instead into the namespace for the schema instance, I am sure that the error is on your platform.


update : OK, your update says that you are trying to use <xs:include> to indicate types in a different namespace. You cannot do this - <xs:include> always casts the included elements to the same namespace as the parent schema document. If they are for a different namespace, you should use <xs:import> .

If you want to refer to one of the element definitions in an imported namespace schema without a name, then you need to find a way to assign a prefix to the namespace "without namespace". If it had a prefix, you could refer to them as follows:

 <xs:element ref="nn:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA"/> 

Try adding the xmlns:nn="" attribute to the parent schema document, see if this works.

+3
source

All Articles