none
Remove space and namespace in Xml File RRS feed

  • Question

  • Hi All,

    Through BizTalk I am getting the following xml file as output :

    <?xml version="1.0" encoding="utf-8"?>

    <ns0:Employess xmlns:ns0="http://MyProject.Test">

    <Employee>

    <FirstName> </FirstName>

    <LastName>Sajwan</LastName>

    </Employee>

    <Employee>

    <FirstName>Prakash</FirstName>

    <LastName> </LastName>

    </Employee>

    </ns0:Employess>

    Now I want to remove space from <FirstName> </FirstName>  and <LastName> </LastName> element if it contains space.

    I also want to remove namespace from the xml file.How it is possible ?

    Could we do it in encoding stage in custom pipeline ?


    Prakash


    • Edited by Shivay_ Thursday, July 2, 2015 7:21 AM
    Thursday, July 2, 2015 7:20 AM

Answers

  • Hi ,

    You can apply a inbound mapping at your receive port . This will be simple approach were you need to create one more schema as per your requirement (without name space or modified name space) .

    Once schema is created you can do one to one mapping of all the elements expect Firstname ,Last name . For these elements which are having white space ,you can apply below C#script to remove the blank space .

    public string removeSpace(string param1)
    {
     return param1.Replace(" ", "");
    }
     

    Thanks

    Abhishek


    • Marked as answer by Shivay_ Saturday, July 4, 2015 5:19 AM
    Thursday, July 2, 2015 7:42 AM

All replies

  • Hi ,

    You can apply a inbound mapping at your receive port . This will be simple approach were you need to create one more schema as per your requirement (without name space or modified name space) .

    Once schema is created you can do one to one mapping of all the elements expect Firstname ,Last name . For these elements which are having white space ,you can apply below C#script to remove the blank space .

    public string removeSpace(string param1)
    {
     return param1.Replace(" ", "");
    }
     

    Thanks

    Abhishek


    • Marked as answer by Shivay_ Saturday, July 4, 2015 5:19 AM
    Thursday, July 2, 2015 7:42 AM
  • hi Prakash,

    You can use a pipeline (I mean create) which has a namespace remover pipeline component.

    Refer to https://msdn.microsoft.com/en-us/library/ee250047(v=bts.10).aspx

    or

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

    Removing spaces is a little twisted (in the sense).. you will find many MSDN threads where retaining spaces was needed but when passing through BizTalk they were being removed etc.,

    Can you let us know if these are being introduced or is it just coming as inputs?


    Praveen Behara
    MCST : BizTalk Server 2006 R2, 2010

    Thursday, July 2, 2015 7:44 AM
  • Hi,

    You can use also a BizTalk map in the send port to remove the namespaces of the XML file.

    It's very comfortable because you don't need any custom C# code.

    You have to set the following custom XSLT in the map:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <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>

    Regards


    When an answer is helpful, please vote as helpful, propose as answer and/or mark as answer

    Thursday, July 2, 2015 8:24 AM
  • Can you clarify something, are you receiving this from an external system or creating it yourself?

    The correct way to remove the spaces is through Map.  Note, how you do it depends on the receiver's expectation so there isn't enough here to give complete advice.

    Exactly why do you want to remove the namespace? Yes, it does matter.

    Thursday, July 2, 2015 10:18 AM
    Moderator