简体   繁体   English

XSD文件,在哪里获取xmlns参数?

[英]XSD file, where to get xmlns argument?

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="abc" targetNamespace="http://schemas.businessNameHere.com/SoftwareNameHere" 
           elementFormDefault="qualified" 
           xmlns="http://schemas.businessNameHere.com/SoftwareNameHere" 
           xmlns:mstns="http://schemas.businessNameHere.com/SoftwareNameHere" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="..." type="..." />
<xs:complexType name="...">

I am working on a project using XSD to generate .cs file. 我正在使用XSD生成.cs文件的项目。 My question is concerning the string " http://schemas.businessNameHere.com/SoftwareNameHere " If I change it, it doesn't work. 我的问题是关于字符串“ http://schemas.businessNameHere.com/SoftwareNameHere ”如果我改变它,它不起作用。 But the http:// is not a valid one... what is the logic behind and where can I can information about what to put there or how to change it? 但是http://不是一个有效的......背后的逻辑是什么,我在哪里可以获得有关放在那里或如何更改它的信息?

XSD namespaces do not have to be valid URI's. XSD名称空间不必是有效的URI。 Having a namespace string that is a URL doesn't mean anything is fetched from the URL, or anything to do with the web at all - it's simply a string like any other. 拥有一个URL的命名空间字符串并不意味着从URL中获取任何内容,或者根本不需要与Web进行任何操作 - 它只是一个像其他任何字符串一样的字符串。 So although the URL may be invalid from the sense that it doesn't actually point to anything, it's still a valid string as a namespace declaration. 因此,尽管URL实际上并不指向任何内容,但它可能是无效的,但它仍然是一个有效的字符串作为名称空间声明。

You can read up on some of the reasoning behind namespace identifiers being in this format here . 您可以在此处阅读这种格式的命名空间标识符背后的一些推理

There are several reasons for using URL's as a namespace identifier, but mainly it is for convenience - it's a unique identifier that generally has some meaning attached to it for the users, much like the way Java namespaces classically begin with "com", "org" or "net". 使用URL作为命名空间标识符有几个原因,但主要是为了方便起见 - 它是一个唯一的标识符,通常为用户附加了一些含义,就像Java命名空间通常以“com”开头的方式一样,“org” “或”网“。

For the nitty gritty of why namespaces are in URI (technically, IRI ) format, you can read the W3C's standards for XML namespaces . 有关为什么命名空间为URI(技术上, IRI )格式的细节,您可以阅读W3C的XML命名空间标准 The specify that XML Namespaces are in IRI (International Resource Identifier) format, defined in RFC3986 . 指定XML命名空间采用RFC3986中定义的IRI(国际资源标识符)格式。

For more information on how to properly use namespaces, there are lots of great walkthroughs, like this one . 有关如何正确使用命名空间的更多信息,有很多很棒的演练, 比如这个 What isn't working when you change the namespace? 更改命名空间时什么不起作用?

The namespace does not have semantic meaning beyond having to be unique. 命名空间除了必须是唯一的之外没有语义含义。 People normally use a URI form as that may point to documentation, but this is not a requirement. 人们通常使用URI表单,因为它可能指向文档,但这不是必需的。

In this case, it is the default namespace and it is possible that the application that you are using to generate your .cs files is hardcoded to use it. 在这种情况下,它是默认命名空间,您用于生成.cs文件的应用程序可能会被硬编码以使用它。

In a well written application, nothing should break if you simply change a namespace string. 在编写良好的应用程序中,如果只是更改命名空间字符串,则不应该破坏任

xmlns="http://schemas.businessNameHere.com/SoftwareNameHere" 

This is not a valid URL where some document has to exist - it's only a string that represents a XML namespace (like a namespace in your C# application called System.Data or whatever). 不是一个有效的URL,其中某些文档必须存在 - 它只是一个表示XML命名空间的字符串(如C#应用程序中名为System.Data或其他任何名称的命名空间)。

You can easily change that string - there's nothing being referenced here. 您可以轻松更改该字符串 - 这里没有引用任何内容 (but that's a common misconception) (但这是一种常见的误解)

People often use the URL-syntax because the domain registered to you / your company is guaranteed to be unique worldwide -> thus the XML namespace you derive from it will also be unique worldwide. 人们经常使用URL语法,因为注册到您/您公司的域保证在全球范围内是唯一的 - >因此,您从中获得的XML命名空间在全球范围内也是独一无二的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM