xml targetNamespace

10:13:00 PM 0 Comments

argetNamespace是一个xml的schema中的概念 
比如我们定义了这么个schema: 
<xs:schema   xmlns:xs= "http://www.w3.org/2001/XMLSchema
targetNamespace= "http://a.name/space "> 
<xs:element   name= "address "   type= "xs:string "   /> 
</xs:schema> 
那么它表示的意思是address这个元素是属于 "http://a.name/space "命名空间的。你想想看,如果你不指定targetNamespace,那么address是属于什么命名空间是不知道的,它肯定不是属于 "http://www.w3.org/2001/XMLSchema"命名空间。指定了这个以后,就能让我们定义的schema中的元素都有自己的命名 空间。这个命名空间都是自己定义的。
根据我的理解TargetNameSpace只在定义XML SCHAME的时候才有用,它的主要作用是标明Schame定义的元素的命名空间,而DefaultNameSpace则只是标明在定义这个Schame 中用的默认命名空间比如:<a href='http://www.w3.org/2001/XMLSchema'>http://www.w3.org/2001/XMLSchema 就是在定义一个XSD的时候的默认命名空间,而定义出来的Schame的命名空间则是根据需要指定。 
下面是W3C( http://www.w3.org/TR/2004/PER-xmlschema-0-20040318/#NS )上关于这个问题的解释: 
A schema can be viewed as a collection (vocabulary) of type definitions and element declarations whose names belong to a particular namespace called a target namespace. Target namespaces enable us to distinguish between definitions and declarations from different vocabularies. For example, target namespaces would enable us to distinguish between the declaration for element   in the XML Schema language vocabulary, and a declaration for element in a hypothetical chemistry language vocabulary. The former is part of the http://www.w3.org/2001/XMLSchema target namespace, and the latter is part of another target namespace. 
When we want to check that an instance document conforms to one or more schemas (through a process called schema validation), we need to identify which element and attribute declarations and type definitions in the schemas should be used to check which elements and attributes in the instance document. The target namespace plays an important role in the identification process. We examine the role of the target namespace in the next section. 
The schema author also has several options that affect how the identities of elements and attributes are represented in instance documents. More specifically, the author can decide whether or not the appearance of locally declared elements and attributes in an instance must be qualified by a namespace, using either an explicit prefix or implicitly by default. The schema author's choice regarding qualification of local elements and attributes has a number of implications regarding the structures of schemas and instance documents, and we examine some of these implications in the following sections

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard.