Ravindar, Biztalk Developer and Administrator

Just another BizTalk blog

Replace “<" symbol from a not well formatted xml of a particual schema

In the below code the variabl TagsArray, define the tags like .
only include start tag, do not include ending tags lik

public string ReplaceLessThanSymbol(string xmldocument)
{
string ResultingXmlString = xmldocument;
string[] TagsArray = { “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “”, “” };

int firstSearchEndLocation = ResultingXmlString.Length;
for (int i = 0; i 0)
{

//find existance
int k = ResultingXmlString.LastIndexOf(TagsArray[i], firstSearchEndLocation, firstSearchEndLocation);
int substringfrom = k + TagsArray[i].Length;
string CurrentTagEndTag = TagsArray[i].Insert(1, “/”);
//find next existance
int SubstringTo = ResultingXmlString.LastIndexOf(CurrentTagEndTag, firstSearchEndLocation, firstSearchEndLocation);
if (k > 0 && SubstringTo > 0)
{
string output = ResultingXmlString.Substring(substringfrom, SubstringTo – substringfrom);
string substring1 = ResultingXmlString.Substring(0, substringfrom);
string substring2 = ResultingXmlString.Substring(SubstringTo, ResultingXmlString.Length – SubstringTo);
int firstSearchEndingPoint = output.Length;
for (int m = 0; m < output.Length; m++)
{
//to Replace 0)
{

int lastIndexofLessThanSymbol = output.LastIndexOf(‘ 0)
{
firstSearchEndLocation = lastIndexofLessThanSymbol;
try
{
if (output[lastIndexofLessThanSymbol + 1] == ‘/’)
{
}
else
{
bool isItStartingTag = false;
//check if it is starting tag
for (int count = 0; count output.Length)
{
isItStartingTag = false;
}
else
{

//string startingTag = output.Substring(lastIndexofLessThanSymbol, TagsArray[count].Length + 1);
string startingTag = output.Substring(lastIndexofLessThanSymbol, TagsArray[count].Length);

for (int l = 0; l “)
output = output.Substring(0, lastIndexofLessThanSymbol) + “” + output.Substring(lastIndexofLessThanSymbol + 1, output.Length – lastIndexofLessThanSymbol – 1);
}

}
}
catch (Exception ex)
{
output = output.Substring(0, lastIndexofLessThanSymbol) + “” + output.Substring(lastIndexofLessThanSymbol + 1, output.Length – lastIndexofLessThanSymbol – 1);
}
firstSearchEndingPoint = lastIndexofLessThanSymbol;
}
else
{
firstSearchEndingPoint = 0;
}
}

}
ResultingXmlString = substring1 + output + substring2;
firstSearchEndLocation = k;
}
else
{
firstSearchEndLocation = 0;
}
}
}

//ResultingXmlString = ResultingXmlString.Replace(“&”, “amp;”);
return ResultingXmlString;
}

Advertisements

April 20, 2010 - Posted by | Asp.Net, Biztalk Server

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: