For example, to put a pound (or hash) sign # in an XML file, you can use either of the following:

ASCII decimal and Hex values in XML

 # 
 or
 # 

23 in hex = 2×16+3 = 35 in decimal

So the syntax is the ampersand and the hash tag followed by the number, then followed by a semicolon.
If doing hex, add the letter “x” before the number.

One more example, a Carriage Return/Line Feed:

 
 
 or
 
&x0A; 

You can find an example ASCII character chart here.

How to encode other characters, such as ampersand, a double or single quote

Other common shortcuts (called entity references) are:

&  ampersand sign 
<  less than sign 
>  greater than sign 
" for a double quote 
' for a single quote (apostrophe) 

CDATA turns off parsing

For long strings where you want to turn off the parser temporarily (in order to allow special characters): '
Other common shortcuts are:

<![CDATA[  anything goes here, such as &, <, > and so on ]]>

Copy and paste from here: 
<![CDATA[  ]]>
and replace the inner brackets with your CDATA text. 

Trademark and Copyright Symbols

Other common symbols are:

Registered Trademark: &#174; and Copyright: &#169;

I got this error when doing custom XSLT with a BizTalk map.

It was a case of “brain fog”. The proper keyword is xsl:choose, not xsl:case. Other languages call this a switch or a case. I just temporarily forgot that XSLT calls it a “choose”.

Example of what the xsl:choose looks like (from https://www.w3schools.com/xml/xsl_choose.asp

<xsl:choose>
  <xsl:when test="expression">
    ... some output ...
  </xsl:when>
  <xsl:otherwise>
    ... some output ....
  </xsl:otherwise>
</xsl:choose>

This is a run-time error can occur when you use a map that is XSLT based. It is possible to compile and deploy the project, even when the XSLT is malformed or has errors in it.

Try to reproduce in the developer environment with one or both of the following:
1) Open your project in Visual Studio, and do a test map with some real incoming data.
2) Make sure you XSLT is well-formed XML.
3) You might also try validating the map (right-click validate)

I also saw this happen when I removed a “Logical Existence” functoid, and the an XSLT functoid was using it as follows:

			<xsl:variable name="var:v14A" select="userCSharp:LogicalExistence(boolean(L004))" />

By doing the “test map”, it gave the error:
Extension object ‘http://schemas.microsoft.com/BizTalk/2003/userCSharp’ does not contain a matching ‘LogicalExistence’ method that has 1 parameter(s).

Using the following Reg-Ex (Regular Expression) to find UTF-8 or UTF-16 characters in a text file;
this should work with any editor that supports Reg-Ex, such as NotePad++ or Visual Studio.

Be sure and check the “Regular Expression” option on the search, then type in the find string: [x80-xFF]

FULL ERROR

Exception: System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://tempuri.org/:ExportValuationPolicyNumberResult. The InnerException message was ‘Type ‘TFBIC.RCT.WCFWebServices.ExpressLync.MainStreetValuation’ with data contract name ‘MainStreetValuation:http://schemas.datacontract.org/2004/07/TFBIC.RCT.WCFWebServices.ExpressLync’ is not expected. Add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.’. Please see InnerException for more details. —> System.Runtime.Serialization.SerializationException: Type ‘TFBIC.RCT.WCFWebServices.ExpressLync.MainStreetValuation’ with data contract name ‘MainStreetValuation:http://schemas.datacontract.org/2004/07/TFBIC.RCT.WCFWebServices.ExpressLync’ is not expected. Add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

SOLUTION

1. Manually create a proxy to the WCF Service from the command line like so:
svcutil /serializer:XmlSerializer http://localhost:46122/ValuationService.svc

2. Add the [XmlSerializerFormat] to your ServiceContract on the WCF Service

By doing this, we force our WCF Service to use the XmlSerializer rather than the default DataContractSerializer. Note: you?ll need to call the WCF service from you new proxy in your sample code.

Converts several date/time formats to standard XML Date/ Time


        /// <summary>
        /// This takes a vendor's non-standard dates, such as 5/1/2008 and formats as XML Date.
        /// (i.e. the month may one or two digits, the day may be one or two digits).
        /// Neal Walters - changed on 09/03/2008 to  throw exception. 
        /// also tested to make sure it handles all the following dates (and it does)
        ///    string testDate1 = "03/09/2008";
        ///    string testDate2 = "1999-05-31";
        ///    string testDate3 = "03/09/2008 10:50:16.157";
        ///    string testDate4 = "1999-05-31T13:20:00.000-05:00";
        ///    string testDate5 = "2008-09-03 10:50:16.157";
        ///    string testDate6 = "2008-09-32";
        /// </summary>
        /// <param name="inDate"></param>
        /// <returns></returns>
        public static string ConvertDateTimetoXmlDateTime(string inDate)
        {
            try
            {
                DateTime dtIn = DateTime.Parse(inDate);
                return System.Xml.XmlConvert.ToString(dtIn, System.Xml.XmlDateTimeSerializationMode.Local);

            }
            catch
            {
                string errorMessage = "invalid-Date/Time-conversion from value='" + inDate + "'";
                throw new Exception(errorMessage);
                //return errorMessage;
            }
        }

This code builds an xml document in memory, then returns it as an System.Xml.XmlDocument. It also show the proper way to build an XML date.

        /// <summary>
        /// This routine is needed when an in-bound endpoint has a map failure when translating
        /// inbound schema to  TMXML. 
        /// </summary>
        /// <returns></returns>
        public static XmlDocument ReturnNewTMXML()
        {
            DateTime currentDateTime = DateTime.Now;
            string strDateTime = currentDateTime.ToLongDateString();

            string strMyDoc =
            "<n2:MyRootEl xsi:schemaLocation='http://MyNamespace.MySchema.xsd' +
'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
                "<source>" +
                  "<objectId>NULL</objectId>" +
                  "<objectType>NULL</objectType>" +
                  "<requestor>NULL</requestor>" +
                  "<transactionGuid>NULL</transactionGuid>" +
                  "<requestType>NULL</requestType>" +
                  "<dateTimeReceived>" + TFBIC.Common.BizTalk.Components.MapHelper.ConvertDateTimetoXmlDateTime(strDateTime) + "</dateTimeReceived>" +
                  "<isResponseExpected>false</isResponseExpected>" +
                "</source>" +
            "</n2:MyRootEl>";

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.PreserveWhitespace = true; //making sure no whitespaces get added
            xmlDoc.LoadXml(strTMXML);
            return xmlDoc;

        }

This sample shows how to build an XML node and add it as a new child in an existing

        /// <summary>
        /// This routine is needed when an in-bound endpoint Sends TMXML with no Itinerary Node in the Header
        /// The Receiver must make sure that the Itinerary node is present in the Header.
        /// </summary>
        /// <returns></returns>
        public static XmlDocument AddItineraryNode(XmlDocument xmlDoc)
        {
            xmlDoc.PreserveWhitespace = true; //making sure no whitespaces get added
            string strXPath = "//*[local-name()='ItineraryStep']";
            string strItinerary =
                    "<policyName>NULL</policyName>" +
                     "<status>NULL</status>" +
                     "<currentStepName>NULL</currentStepName>" +
                     "<currentStepStatus>NULL</currentStepStatus>" +
                     "<currentStepIndex>0</currentStepIndex>" +
                     "<currentStepErrorType>NULL</currentStepErrorType>" +
                     "<currentProcessCode>NULL</currentProcessCode>" +
                     "<currentProcessMethod>NULL</currentProcessMethod>" +
                     "<itinerarySteps></itinerarySteps>";
            XmlNamespaceManager iMgr = new XmlNamespaceManager(xmlDoc.NameTable);
            XmlNode nodeItin = xmlDoc.SelectSingleNode(strXPath, iMgr);

            if (nodeItin == null)
            {
                XmlElement newItinerary = xmlDoc.CreateElement("Itinerary");
                newItinerary.InnerXml = strItinerary;
                xmlDoc.DocumentElement.FirstChild.AppendChild(newItinerary);
            }

            return xmlDoc;

        }


In the following example, ExceptionLog table has an xml column called TMXML. This contains a canonical xml message. The SQL can “peer” into the xml column, and pull out selected fields.

SELECT
  eventDateTime,
  TMXML.value('/*[local-name()="TMXML"][1]/*[local-name()="Header"][1]/*[local-name()="Source"][1]/requestType[1]',
  'varchar(24)') AS RequestType,
  TMXML.value('/*[local-name()="TMXML"][1]/*[local-name()="Header"][1]/*[local-name()="Itinerary"][1]/currentStepName[1]',
  'varchar(24)') AS CurrentStepName,
  TMXML.value('/*[local-name()="TMXML"][1]/*[local-name()="Header"][1]/*[local-name()="Itinerary"][1]/currentProcessCode[1]',
  'varchar(24)') AS CurrentProcessCode
FROM ExceptionLog

A nifty idea is to put the above SQL in a view, and hide the xquery statements from the common user. Then the user can simply do

Select * from ViewExceptionLog

NOTE 1: The xpath must return a single value, else you will get an error something like this:

XQuery [TMXML.value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'


This is why each element in the hierarchy has the [1] after it, to return only the first nonoccurence. Even if you data doesn’t have multiple of them, T-SQL doesn’t know, you have to be explicit.

NOTE 2: if you are copying your xpath from C#, it’s probably easier to replace the single quotes with double quotes, as C# and SQL use the opposite quotes delimiters by default.

NOTE 3: Use a tool like http://www.xpathtester.com/xpath to test your xpath outside of SQL. You can paste your xml text message there, and play with different xpath statements. Then when you have one that works, go back and plug it into your T-SQL query.

For further info: http://msdn.microsoft.com/en-us/library/ms178030.aspx

What if you need to remove all the empty nodes in an XML document? It’ easy with this small subroutine. This might be useful to set fields to NULL when they have no value, especially when communicating between BizTalk and a WCF web service. You might often get serialization errors when, for example, a date/time field has an empty-string value. Better to pass no element to the web service (i.e. NULL) than a field with a bad value.


        public static XmlDocument RemoveEmptyNodes(XmlDocument txd)
        {

           // make a clean copy so we don't accidentally destroy the byRef txd variable passed to us.
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(txd.OuterXml);
            XmlNodeList emptyElements = xmldoc.SelectNodes(@"//*[not(node())]");
            for (int i = emptyElements.Count - 1; i >= 0; i--)
            {
               emptyElements[i].ParentNode.RemoveChild(emptyElements[i]);
            }
            xmldoc.InnerXml = xmldoc.InnerXml.Replace("", "");
            return xmldoc;
        }

You can call the above code from a message assignment shape in an orchestration.
Just put the above code in a C# helper .DLL, make a reference to it from your orchestration, then you should be able to call it statically.