Search code examples
c#xmlbiztalkbiztalk-2013

In-line C# for BizTalk Scripting Functoid


For the XML below, how can I use in-line C# in a scripting functoid to get the value of type where the element = 'SAON'? For info, this is comes from a record within my source schema, the record contains encoded XML which I first of all convert to an XML document.

<?xml version="1.0"?>
<LocationXML>
      <Location>
         <Element>PAON</Element>
         <type>a</type>
      </Location>
      <Location>
         <Element>SAON</Element>
         <type>b</type>
      </Location>
</LocationXML>

In-line C#: This comes from an app I built previously, not been tested in the map as yet but I suspect it's not a million miles away.

string s = NewValueXml;

 XmlDocument x = new XmlDocument();
 x.LoadXml("<root>" + s + "</root>");
return x.InnerText;

Solution

  • Okay, in the scripting functoid that you use to convert the string into an xmldocument, I would do this and return a string then map it to your destination node. Hopefully I understood your question this time...

    public string XMLConvertAndReturnType(string param1)
    {
         string returnType = ""; //or String.Empty
         XmlDocument x = new XmlDocument();
         x.LoadXml("<root>" + param1 + "</root>");
         returnType = x.SelectSingleNode("//Location[Element = 'SAON']/type/text()").Value.ToString();
         return returnType; 
    }