CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeff Lynch [MVP]

Everything E-Commerce!

BizTalk Server 2006: Changing the Outbound Namespace Prefix

I've decided to revise and repost this after seeing a question about this in the microsoft.public.biztalk.general newsgroup.

I've run into an interesting requirement to make sure my outbound xml file uses a specific namespace prefix. Since the BizTalk mapper always generates xml documents with the "ns0" prefix I wasn't quite sure how to accomplish this and posted my question to the microsoft.public.biztalk.general newsgroup. It turns out to be very straight-forward to accomplish.

Step 1: Map as you normally would using the mapper tool.

Step 2: Validate your map and open the xslt generated by BizTalk Server 2004 in your favorite text editor. This file can usually be found in the  "\temp\_mapdata" folder.

Step 3: Replace all instances of the namespace prefix "ns0" with the prefix you require (in my case "pidx") as shown below.

Step 4: Save this xml file as an .xslt file and include it (or add it) into your BizTalk project.

Step 5: Create a new map using the same source and destination schemas you used in Step 1 but use the external xslt you generated by setting the “Custom XSLT Path” property on your new map.

The results are shown in the figure below. No default namespace prefix ("ns0") here!

The link below explains how to use external xslt in your maps.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sdk/htm/ebiz_prog_map_xrkh.asp

Take Away: There is always more than one way to skin a cat! In BTS2006 it may not be obvious how to do something a little unusual.

Technorati Tags: ,


Published Aug 09 2006, 11:58 AM by jlynch
Filed under:

Comments

Bryan Corazza said:

Jeff, That's slick. I've always handled those in custom classes or xslt outside of BizTalk. Very handy.
# July 25, 2005 9:17 PM

DonXML said:

I guess the bigger question is why would you care?  The prefix just a short cut to refer to the namespace, and developers should never care what prefix is used for an XML document.  Semantically, pidx:Invoice and ns0:Invoice are the same thing (assuming that both pidx and ns0 map to the same namespace).
# August 9, 2006 9:29 PM

jlynch said:

Don,

I agree technically, except that our trading partners REQUIRE that both the namespace and prefix exactly match what they expect. I suspect that their Unix based "integration" software is not altogether standards compliant when it comes to XML. When the trading partner in question is one of our largest customers doing millions in B2B transactions, we generally make every attempt to comply with their wishes. It still beats having to process custom EDI flat-file formats!

Thanks for reading and commenting!

Jeff
# August 10, 2006 9:47 AM

DonXML said:

Jeff, yep, I totally agree about doing what your trading partners require.  It is a shame that in 2006 some big shops still can't get simple XML right.  Sounds like they are using RegEx to parse the XML instead of a real XML Parser (it isn't like I haven't seen that before).
# August 10, 2006 8:59 PM

Richard said:

Thanks for this, i've spent all day trying to sort this. My issue stems from using infopath and sharepoint with biztalk. If you want to access the columns in an infopath form inside your sharepoint library, then creating an instance of a document from the XSD file creates a namespace pattern that must be in an incoming document or the column data will not appear in your sharepoint library. As my biztalk mapper creates my xml instance and I pass this into the library via the WSS adapter for sharepoint my namespace is always ns0. Sharepoint will accept the file and allow it to be opened in either forms services or info path client, but it will not show column data unless the namespace tag matches. This tag never matches if you have biztalk promoted properties in your xml schema. Thanks for the help!
# October 5, 2007 7:33 PM

InfoPath 2007 Scenarios With BizTalk Server 2006 R2 « Richard Seroter’s Architecture Musings said:

Pingback from  InfoPath 2007 Scenarios With BizTalk Server 2006 R2 « Richard Seroter’s Architecture Musings

# December 5, 2007 1:20 PM

Scott Banwart’s Blog » Blog Archive » Sharepoint 2007 and XML Namespace Prefixes said:

Pingback from Scott Banwart’s Blog » Blog Archive » Sharepoint 2007 and XML Namespace Prefixes
# March 5, 2008 9:06 AM

Pauline Johnson said:

Great solution but what if I do not want a prefix on each node of my output document?
# March 14, 2008 8:37 AM

jlynch said:

Pauline,

You can set the elementFormDefault attribute in your schema to "unqualified" to accomplish this.

Jeff

# March 22, 2008 3:56 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication