Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xsd xmln:tns和targetNamespace_Xsd_Xml Namespaces - Fatal编程技术网

Xsd xmln:tns和targetNamespace

Xsd xmln:tns和targetNamespace,xsd,xml-namespaces,Xsd,Xml Namespaces,我看到一些XSD模式文档在其顶部的schema元素中声明了targetNamespace和xmlns:tns属性。例如,采取以下措施。它们似乎也有相同的字符串值。我理解targetNamespace的作用,但是xmlns:tns在这上面做什么呢 <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http:

我看到一些XSD模式文档在其顶部的
schema
元素中声明了
targetNamespace
xmlns:tns
属性。例如,采取以下措施。它们似乎也有相同的字符串值。我理解
targetNamespace
的作用,但是
xmlns:tns
在这上面做什么呢

<?xml version="1.0" encoding="UTF-8"?>
<schema
    xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/Product"
    xmlns:tns="http://www.example.org/Product"
    elementFormDefault="qualified">
...

...

它允许您稍后在模式中引用名称空间。例如,如果您声明一个命名类型,然后还要声明该类型的元素

<complexType name="someType">
  <!-- ... -->
</complexType>

<element name="someElement" type="tns:someType" />


简单地说
type=“someType”
是行不通的,因为这是指
someType中的(不存在的)
someType
http://www.w3.org/2001/XMLSchema
命名空间(架构文件的
xmlns=“…”
)而不是
http://www.example.org/Product
名称空间。

确定,因此,从这个意义上讲,“tns”就像绑定到名称空间的任何其他前缀一样,它没有任何特殊意义,就像所有其他前缀一样,对吗?@MarcusJuniusBrutus确实,你可以使用任何你喜欢的前缀。前缀
tns
在本上下文中作为“目标名称空间”的助记符很常见,但您也可以使用
product
ns0
,或者其他任何形式。如果您有“xmlns:tns”,您需要“targetNamespace”吗?我试图使用另一个组的XSD,它有“xmlns:tns”但没有“targetNamespace”。@MikeStoddart它们通常一起出现,很简单,当您有一个带有
targetNamespace
的模式时,您需要一个前缀,如
tns:
,以便能够从其他地方引用模式中声明的类型和元素。如果架构没有
targetNamespace
,则其类型不在命名空间中,因此交叉引用不需要前缀。这可能只是因为
xmlns:tns
是早期编辑的遗留内容,模式中没有任何引用实际使用
tns:anything