21475

I need my BizTalk map to stop converting xml:lang to ns1:lang

Question:

I have a map in BizTalk 2009 that is converting some data into an XML document to be sent on to another system. The target schema includes some elements with xml:lang attributes. BizTalk generates those as ns1:lang. The target system requires that the prefix xml be used.

Here is a simplified example to show what BizTalk is doing:

<strong>sample.xsd</strong>

<xs:schema targetNamespace="http://example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import schemaLocation="common.xsd" namespace="http://www.w3.org/XML/1998/namespace" /> <xs:element name="example"> <xs:complexType> <xs:attribute ref="xml:lang" /> </xs:complexType> </xs:element> </xs:schema>

<strong>common.xsd</strong>

<xs:schema xmlns:xml="http://www.w3.org/XML/1998/namespace" targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:attribute name="lang" type="xs:language" /> </xs:schema>

<strong>Example of map output</strong>

<ns0:example xmlns:ns0="http://example.com/" xmlns:ns1="http://www.w3.org/XML/1998/namespace" ns1:lang="en-US" />

Is there some way to convince BizTalk to use the xml prefix?

Answer1:

As far as I know, there is no builtin way for achieving this.

There are, however, two solutions that I can see:

<strong>Use a Custom XML StyleSheet</strong>

If you right-clik on the map and look carefully in the generated xsl stylesheet, you'll see a XML namespace declaration like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://www.w3.org/XML/1998/namespace" ... > ... <xsl:attribute name="ns1:lang"> ...

This is the default behaviour of the BizTalk mapper and you cannot do anything about it. However, if you proceed to extract the generated XSLT and use this as the backend for your map, you can change this declaration to match the expected outcome.

<ul><li>First, copy the stylesheet to the location of your project.</li> <li>Include this stylesheet as a file in your BizTalk project</li> <li>Update the stylesheet, so that the namespace declaration and the matching attribute prefix are correct.</li> </ul>

The resulting xsl stylesheet looks like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xml="http://www.w3.org/XML/1998/namespace" ... > ... <xsl:attribute name="xml:lang"> ...

Now you can use this custom stylesheet as a backend for the map.

<ul><li>In Visual Studio, open the map.</li> <li>Click anywhere on a blank space in the BizTalk designer surface.</li> <li>In the map properties, locate the <em>Custom XSL Path</em> and specify the location of your custom stylesheet.</li> </ul>

<img alt="Custom BizTalk Mapper XSL Path" class="b-lazy" data-src="https://i.stack.imgur.com/THzjp.png" data-original="https://i.stack.imgur.com/THzjp.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

<strong>Use a Custom Pipeline Component</strong>

What you're after is that the message is correct for your target recipient. So the idea is to change the offending namespace prefix as part of sending the message outside BizTalk. The transformation happens during the processing of the send pipeline.

<a href="http://blogs.objectsharp.com/cs/blogs/nbarden/default.aspx" rel="nofollow">Nic Barden</a> has blogged and provided some source code <a href="http://blogs.objectsharp.com/cs/blogs/nbarden/archive/2008/04/28/developing-streaming-pipeline-components-part-5.aspx" rel="nofollow">about this here</a>. You can use his sample as the basis for performing replacement of namespace prefixes, rather than replacing namespaces themselves.

I strongly encourage you to check out the whole series of posts he's done about Developing Streaming Pipeline Components. Nic has made an extensive and thorough job of describing all that's needed to author robust and enterprise-class pipeline components.

<ul><li><a href="http://blogs.objectsharp.com/cs/blogs/nbarden/archive/2008/04/14/developing-streaming-pipeline-components-part-1.aspx" rel="nofollow">Part 1</a></li> <li><a href="http://blogs.objectsharp.com/cs/blogs/nbarden/archive/2008/04/17/developing-streaming-pipeline-components-part-2.aspx" rel="nofollow">Part 2</a></li> <li><a href="http://blogs.objectsharp.com/cs/blogs/nbarden/archive/2008/04/22/developing-streaming-pipeline-components-part-3.aspx" rel="nofollow">Part 3</a></li> <li><a href="http://blogs.objectsharp.com/cs/blogs/nbarden/archive/2008/04/24/developing-streaming-pipeline-components-part-4.aspx" rel="nofollow">Part 4</a></li> <li><a href="http://blogs.objectsharp.com/cs/blogs/nbarden/archive/2008/04/28/developing-streaming-pipeline-components-part-5.aspx" rel="nofollow">Part 5</a></li> </ul>

Answer2:

The easier way to do it and have everything work is to just add the namespace declaration at the beginning of the schema definition like this.

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xml="http://www.w3.org/XML/1998/namespace"> <xs:import schemaLocation="xml.xsd" namespace="http://www.w3.org/XML/1998/namespace" />

Answer3:

In addition to Maxime's suggestions, here are the other possibilities I've found:

<strong>Ignore it and hope that the vendor’s API will take it.</strong>

I don’t think this will work. When I test the map, BizTalk gives me this error:

Output validation error: Prefix 'ns1' cannot be mapped to namespace name reserved for "xml" or "xmlns".

Hello, BizTalk!? You’re the one who decided to use ns1. Don’t complain about it to me!

<strong>Use an XSL-based script functoid to force the output.</strong>

This is based on <a href="http://social.msdn.microsoft.com/Forums/en-US/biztalkgeneral/thread/41c619a3-90d9-48b2-acbe-ed65f41023f7/" rel="nofollow">the suggestion I received on the BizTalk forums</a>. It requires that we fudge the output schema to use a dummy attribute that gets replaced with the xml:lang attribute by the functoid.`

<strong>Add a search/replace expression</strong>

Take the orchestration that calls the map and add an expression after it that would take the XML we’re sending to the vendor and run it through a search/replace regex to fix the namespace prefixes.

Recommend

  • Only get android contacts that are saved to the phone or sim
  • Where does DTOS as InputModel / ViewModel Fit in Layered Archicture
  • Automating exslt:node-set?
  • finding maximum depth of chapter
  • How to implement xsl
  • Merging two XPathDocuments using XmlCompiledTransform
  • How to distinguish field that requires null=True when blank=True is set in Django models?
  • Duplicate Element x number of times with XSLT
  • Find substring in string using locale
  • Majority function in SQL
  • Implicit property animations do not work with CAReplicatorLayer?
  • Change the width of the JQM panels
  • NetBeans doesn't see style.css [duplicate]
  • Jackson mapper write id instead of entire object
  • How to separate filename from path? basename() versus preg_split() with array_pop()
  • What's a fast (non-loop) way to apply a dict to a ndarray (meaning use elements as keys and rep
  • How to extract a number from a string [duplicate]
  • Hibernate in Glassfish - Ejb3Configuration NoClassDefFoundError
  • how to display   in Mozilla using XSL.
  • What is the likely cause of a net::ERR_CONNECTION_ABORTED when uploading a file to Spring
  • How to use the resource module to measure the running time of a function?
  • How to add regEx in angular filter
  • Cursor in wrong place in contenteditable
  • What Makes These Two Array Adds Different?
  • Google Places API - Find a company's CID and LRD
  • Spring integration inbound-gateway Fire an event when queue is empty
  • XSLT foreach repeating nodes to flat
  • Cloud Code function running twice
  • NUnit 3.0 TestCase const custom object arguments
  • How to get current document uri in XSLT?
  • Adjust width of select element according to selected option's width
  • Converting a WriteableBitmap image ToArray in UWP
  • Jquery UI tool tip close icon
  • Array.prototype.includes - not transformed with babel
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • Modifying destination and filename of gulp-svg-sprite
  • GridView Sorting works once only
  • Add sale price programmatically to product variations
  • How to Embed XSL into XML