1.2. XML Namespaces

Namespaces in XML documents are conceptually the same as namespaces in .NET. Any types you define are "enclosed" within the context of the specified namespace. This ensures against name clashes and allows content from multiple sources to be stored within the same document but still be isolated, as required.

Namespaces are used within XML documents and, therefore, BizTalk messages. Namespaces can often be the cause for problems when integrating different systems, when a message doesn't use the correct namespace and, therefore, doesn't comply with the appropriate schema.

The following XML document specifies that the Person element and its contents are within the "http://www.wiley.com" namespace. (This is called a default namespace.)

<Person xmlns="http://www.wiley.com/person">
  <Name>Lucy</Name>
  <Age>5</Age>
</Person>

The following XML document shows how you can explicitly set the namespaces, in contrast to the default namespace example shown before. The Person element is contained within the "http://www.wiley.com/person" namespace, and the Address element is defined within the "http://www.wiley.com/address" namespace.

Instead of having to prefix the nodes with the full namespace name, you can use aliases. In this instance, we've used ps and ad, which allows easier reading and, of course, a smaller payload on the wire, as less text will need to be transmitted.

<ps:Person xmlns:ps:="http://www.wiley.com/person" xmlns:ad:="http://www.wiley.com/address"> <ps:Name>Lucy</ps:Name> ...

Get Professional BizTalk® Server 2006 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.