Please see my answers below.
In the GovTalkMessage element, I understand where the 2nd part of xsi:schemaLocation comes from, but I'm not sure whether it's possible to determine the first part from the schema itself.
The first part of xsi:schemaLocation
tells what namespace the schema located is associated with. Basically, you are using the namespace http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader for the schema located at http://xmlgw.companieshouse.gov.uk/v1-0/schema/Egov_ch.xsd (for any schema used in xsi:schemaLocation
, it is always the target namespace (see targetNamespace
attribute) of that schema which comes first and then the location)
I don't understand where the xmlns value has come from in either of GovTalkMessage or NameSearchRequest. Is it defined somewhere?
xmlns
is the default namespace. Elements fall under default namespace if they are not qualified by using prefix. In this case the elements GovTalkMessage
and NameSearchRequest
fall under the default namespace referred by xmlns
attributes in your respective schemas.
xmlns:dsig, xmlns:gt are mentioned in the GovTalkMessage schema, but so is xmlns:hd, how do I tell which one's need mentioning in the XML above and which don't?
If you want to use elements or attributes defined by those namespaces (xmlns:dsig
, xmlns:gt
, xmlns:hd
,...) in your XML, you will declare these namespaces. It's like declaring object references in Java and using attributes of those object references at a later point in your program.
Why has NameSearchRequest's xsi:schemaLocation only got one value? I thought that attribute required two values, separated by a space.
If you notice the schema http://xmlgw.companieshouse.gov.uk/v1-0/schema/NameSearch.xsd, which has no target namespace. This is the reason you don't have namespace but just location in this case. But, you have to use xsi:noNamespaceSchemaLocation
instead of xsi:schemaLocation
otherwise xml parsers will throw errors. xsi:schemaLocation
only takes "namespace location" pairs.