Mohamed Radi

Dear all,

after i remove carraige return from my xml, i don't know why i can't see valid xml document.

The Input:

<CIMS_Work_order>
<PONOTIFRECOMMEND>recommendaitons123
456</PONOTIFRECOMMEND>
</CPUBNOTIF>
</CIMS_Work_order>

The Output:

<TDLINE>recommendaitons123</TDLINE><TDLINE>456</TDLINE>

As you see from the output, it treats "</" and ">" as text not at xml open and close tag.

I use two Script functoid to do that:

1. First FUNCTOID:

public string ReplaceItem(string param1)
{
char newLine = '\n';
string NL = newLine.ToString();
param1=param1.Replace(" </","</");
param1=param1.Replace(NL, "</TDLINE><TDLINE>");
param1=param1.Replace(" </","</");
return param1;
}

2. Second Functoid:

public string RemoveSpace(string param1)
{
param1=param1.Replace("\r</","</");
return param1;
}

---

Any comments will be appreciated.




Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Richard Hallgren

The output is valid XML as far as it's within a root element (see example in snippet below).

Code Snippet

<TDLINES>
<TDLINE>recommendaitons123</TDLINE>
<TDLINE>456</TDLINE>
</TDLINES>

I don't know what tool you use look at the output XML where you don't get the right highlighting but as soon as that line exists within a root element it's valid.

Is this causing an error in your mapping

Richard Hallgren

http://www.richardhallgren.com






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

Hi Richard,

Thanks alot for your reply.

I know it looks like valid xml, but when i make view source for the xml file, it gives me the following:

<TDLINE>recommendaitons123&lt;/TDLINE&gt;&lt;TDLINE&gt;456</TDLINE>

As you see, it convert any open deilimetter to be '&lt;' and any close tag to be '&gt;.

I use Visual Studio 2005.

All that i need to know, how can i see xml tags when i make View Source', to be like that:

<TDLINES>
<TDLINE>recommendaitons123</TDLINE>
<TDLINE>456</TDLINE>
</TDLINES>






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Richard Hallgren

Ah! I see.

Maybe you could do the following. I haven't actually set this up myself but it might be worth a try.

Code Snippet
public string ReplaceItem(string param1)
{
char newLine = '\n';
string NL = newLine.ToString();
param1=param1.Replace(" </","</");
param1=param1.Replace(NL, "</TDLINE><TDLINE>");
param1=param1.Replace(" </","</");
XmlDocument doc = new XmlDocument();
doc.LoadXml(param1);
return doc.OuterXml;
}

If it's working I guess you also to change your second functiod in a similar way.

Richard Hallgren

http://www.richardhallgren.com






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

When i add:

XmlDocument doc = new XmlDocument();
doc.LoadXml(param1);
return doc.OuterXml;

to any of the script functoid, it raise the follwoing exception:

"Data at the root level is invalid, Line 1 Position 1".







Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

Any Comments will be appreciated.






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Richard Hallgren

We'll try again Wink

I'd try to solve this a bit differently; I'd use Xslt for this. If you change the scripting functiod to be an

"Inline Xslt Call Template" and add the script below.

Code Snippet
<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />
<xsl:variable name="first" select="substring-before($newlist, ' ')" />
<xsl:variable name="remaining" select="substring-after($newlist, ' ')" />
<TDLINE>
<xsl:value-of select="$first" />
</TDLINE>
<xsl:if test="$remaining">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:template>

This will split the input and loop that list and add TDLINE nodes for every space (basically a newline will be read

as a space unless we preserve white spaces). Connect the PONOTIFRECOMMEND node as input to the functoid and the

TDLINE and the output node.

So in my case the following input:

Code Snippet
<ns0:CIMS_Work_order xmlns:ns0="YourNameSpaceHere">
<PONOTIFRECOMMEND>PONOTIFRECOMMEND123
456</PONOTIFRECOMMEND>
</ns0:CIMS_Work_order>

Will be outputted as:

Code Snippet

<ns0:TDLINES

xmlns:ns0="YourNameSpaceHere"><TDLINE>PONOTIFRECOMMEND123</TDLINE><TDLINE>456</TDLINE></ns0:TDLINES>

IMHO this is cleaner Xml handling (even when considering the messy Xslt) than solving it by building stings using

C#. Let us know if it worked out for you or if you'd like to solve it using C# and need further help with that.

Richard Hallgren
http://www.richardhallgren.com






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

Thanks alot for your help.

but, unfortunitly it doesn't work, and it raised 6 exceptions:

The scripting functoid has no script type set, either external or inline, so proper code cannot be generated for it.

The "Scripting" functoid has 1 input parameter(s), but 0 parameter(s) are expected.

Illegal syntax. Expecting valid start name character.

Tag was not closed. (3 errors)

i use the input file you sent, and i connect the script functoid as you said also(PONOTIFRECOMMEND as Input, TDLINE as ouput).







Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Richard Hallgren

Ok, weird. I've actually set this up and it's working fine for me.

  • Have you changed the type of script to "Inline Xslt Call Template"
  • BizTalk 2006
  • Restarted VS

I'll check some more and see if I can get the same excaptions as you get. Do you get them during compilation or during testing of the map

Richard Hallgren

http://www.richardhallgren.com






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

I got them during testing the map.






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

Hi Richard,

Can you send me the sample project you made to test it, may be because of my complex schema something happen






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

Hi Richard,

i try simple two schemas and after changing some schema properties like 'Min Occurs and Max Occurs' it works very good with xml output.

I will try to see what is the error in the existing schema, may be i have to change some properties like what i did at this demo.

and from now i will try to do like you, help people as i can even if i search for solution for them.

Really I respect people like you, because this is the wisdom of science.

Really appreciate your help






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

Hi,

How can i modify the xslt to make the output of the previous example like that:

<Data>

<TDLINE>123

</Data>

<Data>

<TDLINE>456

</Data>






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Mohamed Radi

Hello,

i find it, you need just to modify the map to the record you want to repeat.






Re: BizTalk R2 General How can i remove Carriage Return From text - Urgent

Leonid Ganeline - MVP

If you realy want to "remove carraige return " why you use
param1=param1.Replace(NL, "</TDLINE><TDLINE>");
not
param1=param1.Replace(NL, " ");