Remove space and namespace in Xml File

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 pipe

July 2nd, 2015 3:27am

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


Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2015 3:49am

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?

July 2nd, 2015 3:51am

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

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2015 4:31am

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.

July 2nd, 2015 6:24am

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


Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2015 7:42am

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


July 2nd, 2015 7:42am

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 PkS (India) Saturday, July 04, 2015 5:19 AM
Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2015 7:42am

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 PkS (India) Saturday, July 04, 2015 5:19 AM
July 2nd, 2015 7:42am

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

Other recent topics Other recent topics