2

If I have the following xsd fragment (using MyRootNs but does not matter)

<xs:complexType name="SomeType">
    <xs:sequence>
        <xs:element name="SomeElement" type="ns1:SomeType" />
        ...

Does this result in

<SomeType xmlns="MyRootNs" xmlns:ns1="MySecondNS">
    <SomeElement>
        ...
    </SomeElement>
</SomeType>

or in

<SomeType xmlns="MyRootNs" xmlns:ns1="MySecondNS">
    <ns1:SomeElement>
        ...
    </ns1:SomeElement>
</SomeType>

I found both in

XSD with elements from other namespace

https://www.codeproject.com/articles/18455/xsd-tutorial-part-of-namespaces

Which one is correct?

Community
  • 1
  • 1
TomB
  • 641
  • 5
  • 17

2 Answers2

0

It doesn't "result in" either. SomeType in your schema is the name of a type, not the name of an element declaration. It might of course also be the name of an element declaration, but we don't know what namespace it is in. Nor can we see where (if anywhere) MySecondNS appears in the schema.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

You've not really provided enough information. As Michael point out you can not create an XML element from a complexType definition.

But either scenario is valid given the right schemas.

I should also point out that in this sample the xmlns:ns1="MySecondNS" statement does nothing, its just declaring a namespace. Once declared it is not used.

<SomeType xmlns="MyRootNs" xmlns:ns1="MySecondNS">
    <SomeElement>
        ...
    </SomeElement>
</SomeType>

Example

If your schema looks like this

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.6978 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" targetNamespace="http://MyNamespce1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:q1="http://MyNamespce1">
    <xs:complexType name="SomeType">
        <xs:sequence>
            <xs:element  name="SomeElement" type="q1:SomeType" minOccurs="0" />
        </xs:sequence>
    </xs:complexType>
    <xs:element name="MyRoot" type="q1:SomeType" />
</xs:schema>

enter image description here

Then Valid XML would look like this

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.6978 (https://www.liquid-technologies.com) -->
<MyRoot xmlns="http://MyNamespce1" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://MyNamespce1 Schema.xsd">
    <SomeElement>
        <SomeElement>
            <SomeElement></SomeElement>
        </SomeElement>
    </SomeElement>
</MyRoot>

or

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.6978 (https://www.liquid-technologies.com) -->
<ns:MyRoot xmlns:ns="http://MyNamespce1" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://MyNamespce1 Schema.xsd">
    <ns:SomeElement>
        <ns:SomeElement>
            <ns:SomeElement></ns:SomeElement>
        </ns:SomeElement>
    </ns:SomeElement>
</ns:MyRoot>

The rules for namespaces are fairly simple within a single file, but get rather complicated when dealing with multiple schema files that are inlucded or imported. I would advise you to understand the rules as they apply to a single schema before trying to understand the effects import/include have on namespaces.

Also it would help if you provide more complete samples in future.

Sprotty
  • 5,676
  • 3
  • 33
  • 52