Removing ns0: prefix from biztalk output schema

Hi all,

I am working on one project and in one output message the output is coming as 

<ns0:RootNode xmlns:ns0="http://www.trashdata.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ns0:document>request</ns0:document>
  <ns0:version>2.14</ns0:version>
  <ns0:transactionControl>
    <ns0:userRefNumber>12345</ns0:userRefNumber>
    <ns0:subscriber xsi:type="ns0:inquirySubscriber">
      <ns0:industryCode>I</ns0:industryCode>
      <ns0:memberCode>3527939</ns0:memberCode>
      <ns0:inquirySubscriberPrefixCode>622</ns0:inquirySubscriberPrefixCode>
      <ns0:password>EH33</ns0:password>
    </ns0:subscriber>
  </ns0:transactionControl>
</ns0:RootNode>

I want's to remove the ns0: from message for this i have set the property of output schema as ElementFromDefault = Unqualified

Output : 

<ns0:RootNode xmlns:ns0="http://www.trashdata.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <document>request</document>
  <version>2.14</version>
  <transactionControl>
    <userRefNumber>12345</userRefNumber>
    <subscriber xsi:type="ns0:inquirySubscriber">
      <industryCode>I</industryCode>
      <memberCode>3527939</memberCode>
      <inquirySubscriberPrefixCode>622</inquirySubscriberPrefixCode>
      <password>EH33</password>
    </subscriber>
  </transactionControl>
</ns0:RootNode>

Expected : 

<RootNode xmlns="http://www.trashdata.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <document>request</document>
  <version>2.14</version>
  <transactionControl>
    <userRefNumber>12345</userRefNumber>
    <subscriber xsi:type="ns0:inquirySubscriber">
      <industryCode>I</industryCode>
      <memberCode>3527939</memberCode>
      <inquirySubscriberPrefixCode>622</inquirySubscriberPrefixCode>
      <password>EH33</password>
    </subscriber>
  </transactionControl>
</RootNode>


I have tried to do this using ESB Pipeline to remove the Namespace but then the output is not what i am looking for it's coming as :

<RootNode>
  <document>request</document>
  <version>2.14</version>
  <transactionControl>
    <userRefNumber>12345</userRefNumber>
    <subscriber xsi:type="ns0:inquirySubscriber">
      <industryCode>I</industryCode>
      <memberCode>3527939</memberCode>
      <inquirySubscriberPrefixCode>622</inquirySubscriberPrefixCode>
      <password>EH33</password>
    </subscriber>
  </transactionControl>
</RootNode>

Not sure how to do this ?

with this output the legacy system is not understanding the message...

is there a easy way to do this on schema level ? some property or something ?

Is it possible to remove ns0: prefix from biztalk message root but still keeping namespace?

July 23rd, 2015 3:05am

Hi Nitin,

You can do that simply by set the schema elements property or both elements and attributes properties to be qualified. To do that follow my steps:

1-      Open your schema

2-      Right Click <Schema> and select properties

3-      Use schema property editior and Set [Element FromDefult] to Qualified, and then set [Attribute FromDefault] to Qualified if you are using attributes in your schema.

After applying the steps above, both XML instances below will be valid:

Instance 1

<ns0:Root xmlns:ns0="http://RandomBizTalkProject.Schema1">

  <Field1>Field1_0</Field1>

  <Field2>Field2_0</Field2>

</ns0:Root>

Instance 2

< Root xmlns="http://RandomBizTalkProject.Schema1">

  <Field1>Field1_0</Field1>

  <Field2>Field2_0</Field2>

</Root>

Regards,

Sharad

Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 3:15am

Hi,

I think that the best way to do this process is by using a BizTalk map with a custom XSLT. In this XSLT, you can remove the used namespaces and generate the output with a global namespace.

For example, the following XSLT removes all the namespace in the XML document processed:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">
        <xsl:copy>
            <xsl:apply-templates />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*">
        <xsl:element name="{local-name()}">
            <xsl:apply-templates select="@* | node()" />
        </xsl:element>
    </xsl:template>

    <xsl:template match="@*">
        <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>

    <xsl:template match="text() | processing-instruction() | comment()">
        <xsl:copy />
    </xsl:template>

</xsl:stylesheet>

With some modifications you can adapt this XSLT to meet your requirements.

Regards.

July 23rd, 2015 3:18am

Hi Nitin,

You would need to write a Custom .net class or BizTalk Map  in order to remove the ns0 prefix from your message .

However you could try to follow following steps if you want to do it.

  • create a message in BizTalk orchestration say Message_1
  • Create a Map using source schema of Message_1 and destination schema say your schema/format which you are going to send Message_out
  • Put the XSLT as suggested in the forum thread here in the map and test it.
  • Use a transform shape in Orchestration to create the Message_2
  • once the map is executed it will generate the message without prefix.
Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 3:19am

Hi Nitin,

You can achieve it using XSLT;

<?xml version="1.0" encoding="utf-8"?>  
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
 
  <xsl:output method="xml" indent="no"/>  
 
  <xsl:template match="/|comment()|processing-instruction()">  
    <xsl:copy> 
      <!-- go process children (applies to root node only) --> 
      <xsl:apply-templates/> 
    </xsl:copy> 
  </xsl:template> 
 
  <xsl:template match="*">  
    <xsl:element name="{local-name()}">  
      <!-- go process attributes and children --> 
      <xsl:apply-templates select="@*|node()"/>  
    </xsl:element> 
  </xsl:template> 
 
  <xsl:template match="@*">  
    <xsl:attribute name="{local-name()}">  
      <xsl:value-of select="."/>  
    </xsl:attribute> 
  </xsl:template> 
 
</xsl:stylesheet> 
 
 
July 23rd, 2015 3:27am

You can also use XmlTranslatorStream at your send pipeline which can do your required message modification .

There are some blog post which you can use

http://blogical.se/blogs/johan/archive/2008/01/07/removing-xml-namespace-in-a-pipeline-component.aspx

http://stackoverflow.com/questions/10631151/how-to-add-custom-namespaces-to-an-incoming-xml-message

public class prefixRemoverStream : XmlTranslatorStream
{
    protected override void TranslateStartElement(
        string prefix, string localName, string nsURI)
    {
        base.TranslateStartElement(null, localName, null);
    }

    protected override void TranslateAttribute()
    {
        if (this.m_reader.Prefix != "NS0")
            base.TranslateAttribute();
    }

    public XmlNamespaceRemoverStream(Stream input)
        : base(new XmlTextReader(input), Encoding.Default)
    { }
}

Also as been suggested above Ohawai XSLT transformation can also work . You need to test the code and see proper transformation is working .

Thanks

Abhishek

Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 6:32am

Are you saying they can handle the namespace but not the prefix?

Anyway, have you tried just setting the Element Form Default to Unqualified in the Schema?

Either way, this really is not you problem and is not a BizTalk problem so the first thing you should do is tell you management that the target app is not Xml compliant and you have to spend extra time accommodating that.

July 23rd, 2015 7:41am

Hi All,

Thanks for all your help ...

Yes Moderator.... that's right namespace but no prefix in it...

i got solution for this...i have implemented the ESB Send Pipeline for this where i am using Remove-namespace and then Add-namespace component in Decode section...

i have set the namespace on send port and it's working fine.

Thanks all.....

Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 3:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics