2016-12-15 42 views
2

私は名前空間

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

または私が見つけた

<SomeType xmlns="MyRootNs" xmlns:ns1="MySecondNS"> 
    <ns1:SomeElement> 
     ... 
    </ns1:SomeElement> 
</SomeType> 
でこの結果をい

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

(MyRootNsを使用しますが問題ではありません)次のXSDフラグメントを持っている場合両方とも

XSD with elements from other namespace

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

どちらが正しいのですか?

答えて

0

「結果」にもなりません。スキーマ内のSomeTypeは、要素宣言の名前ではなく、型の名前です。もちろん、要素宣言の名前でも構いませんが、名前空間がどの名前空間にあるのかわかりません。どこにでもMySecondNSがスキーマにどこにあるのかわかりません。

0

あなたは本当に十分な情報を提供していません。 Michaelが指摘しているように、complexType定義からXML要素を作成することはできません。

しかしどちらのシナリオも正しいスキーマでは有効です。

このサンプルでは、​​xmlns:ns1 = "MySecondNS"ステートメントは何もしません。名前空間を宣言するだけです。一度宣言すると使用されません。

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

あなたのスキーマがこの

<?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

のように見える場合は、有効なXMLがこの

<?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> 
のようになります。

または

<?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> 

名前空間のためのルールは、単一のファイルの中にかなり単純ですが、inlucdedまたはインポートされた複数のスキーマファイルを扱うときにかなり複雑になります。インポート/インクルードがネームスペースに与える影響を理解する前に、単一のスキーマに適用されるルールを理解することをお勧めします。

将来さらに完全なサンプルを提供すると役立ちます。