views:

95

answers:

3
<?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"&gt;
    <xs:element name="..." type="..." />
<xs:complexType name="...">

I am working on a project using XSD to generate .cs file. My question is concerning the string "http://schemas.businessNameHere.com/SoftwareNameHere" If I change it, it doesn't work. 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?

+2  A: 

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.

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.

In a well written application, nothing should break if you simply change a namespace string.

Oded
+6  A: 

XSD namespaces do not have to be valid URI's. 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. 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.

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".

For the nitty gritty of why namespaces are in URI (technically, IRI) format, you can read the W3C's standards for XML namespaces. The specify that XML Namespaces are in IRI (International Resource Identifier) format, defined in RFC3986.

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?

womp
You probably have a typo there - "namespaces do not have to be valid URIs". Mean URLs?
xcut
@xcut: namespaces are URIs, which include URLs.
John Saunders
I'm quite aware of that. That's why it's wrong to say namespace identifiers do not have to be valid URIs. They do, they don't have to be resolvable URLs.
xcut
+2  A: 
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).

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.

marc_s