Sep 262006
 

I have a bunch of tidbits that I have found, and instead of creating a blog entry for each of them, I have put them all together into one big entry. I hope that there is something in this for everyone! 

Items Explained:
1. Using the Flat File Schema you can define custom date formats. One word of caution, in order to use this feature, you have to guarantee that the date is going to be present.

2. Using XPath, you can take advantage of features of XPath, namely count(), substring-before(), substring-after() and all other available XPath functions. Example:

MessageCount=(System.Int32)xpath(CompleteMsg,”count(/*[local-name()=’File’ and namespace-uri()=’http://AppendExample.File’]/*[local-name()=’Record’ and namespace-uri()=’http://AppendExample.Record’])”);

And

FirstName=xpath(IndividualMsg.BodyPart,”substring-before(/*[local-name()=’Record’ and namespace-uri()=’http://AppendExample.Record’]/*[local-name()=’Information’ and namespace-uri()=’’]/@*[local-name()=’Name’ and namespace-uri()=’’],’ ‘)”);

LastName=xpath(IndividualMsg.BodyPart,”substring-after(/*[local-name()=’Record’ and namespace-uri()=’http://AppendExample.Record’]/*[local-name()=’Information’ and namespace-uri()=’’]/@*[local-name()=’Name’ and namespace-uri()=’’],’ ‘)”);

3. Since there is no such thing as an Envelope Schema that can be used in a Flat File scenario, you can use XPath to extract internally the separate documents and manipulate the data as needed. Example:

xpathString=System.String.Format(”/*[local-name()=’File’ and namespace-uri()=’http://AppendExample.File’]/*[local-name()=’Record’ and namespace-uri()=’http://AppendExample.Record’][{0}]”,CurrentRecord);

tempXML=new System.Xml.XmlDocument();

tempXML=xpath(CompleteMsg,xpathString);

4. You don’t need to have a Construct Shape with an internal Message Assignment Shape, you can simply use the Construct Keyword; you can construct multiple messages at the same time. Example:

construct AfterMsg,BeforeMsg
{
   AfterMsg=tempAfterXML;
   BeforeMsg=tempBeforeXML;
}

One word of caution though, if you are using the Tracking Profile Editor to capture data, it will not show as an option, so use this only if you are not going to use the TPE.

5. You can take a message and convert it into text for insertion into database columns: 

tempXMLData=IndividualMsg.BodyPart;
StringWriter=new System.IO.StringWriter();
XmlTextWriter=new System.Xml.XmlTextWriter(StringWriter);
tempXMLData.WriteTo(XmlTextWriter);
rawXmlData=StringWriter.ToString();

6. Using XPath, you can update attributes/elements. Example:

xpathString=System.String.Format(”/*[local-name()=’Request’ and namespace-uri()=’http://exampleDataStore’]/*[local-name()=’sync’ and namespace-uri()=’http://exampleDataStore’]/*[local-name()=’after’ and namespace-uri()=’http://exampleDataStore’]/*[local-name()=’DataStore’ and namespace-uri()=’http://exampleDataStore’][{0}]/@*[local-name()=’FirstName’ and namespace-uri()=’’]”,CurrentRecord);

xpath(tempDBInsertMsg,xpathString)=FirstName;

Word of caution though: you need to make sure that the attribute/element exists, xpath will not create it, just populate it.

7. Using Microsoft’s built in System.XML functionality; you can append data inside of an already existing xml structure. Example:

internalBeforeXmlDocument=IndividualMsg.BodyPart;
tempBeforeXML=(System.Xml.XmlDocument) tempBeforeXML.CloneNode(true);
XmlNode = tempBeforeXML.CreateNode (System.Xml.XmlNodeType.Element,”ns1″,”Record”,”http://appendexample.record/“);
XmlNode.InnerXml=internalBeforeXmlDocument.FirstChild.InnerXml;
tempBeforeXML.FirstChild.AppendChild(XmlNode);
BeforeMsg=tempBeforeXML;

8. Using Multi-part messages, you can call Business Rules to update ‘Context’ data, since the BRC cannot access the Context data, accessing the Context Part of the data serves the same purpose.