I'm pretty new to the Business Rules functionality in BizTalk Server 2006 R2 and I have hit a bit of a problem...
Referencing XML in Biz talk is a breeze if you have an XSD. You simply pick off the elements you want and evaluate them using predicate operators.
What happens though if you have an XSD, but it has some elements that aren't defined it?
e.g. <?xml version="1.0" standalone="yes" ?>
<xsd:element name="CustomDataSet" type="business:ty_custom_xml" minOccurs="0" maxOccurs="1" />
<xsd:any namespace="##any" processContents="skip" maxOccurs="unbounded" />
The XML document that this relates to would look something like :
As I don't know what custom data will appear in here I cannot / don't really want to write these into my XSD what do I do ...?
A custom bit of code I thought...
i.e. Create a function in a .net class and add a reference to it in the Vocabulary that I could call from within a rule policy.
Here's my attempt :
Public Class MyRulesInterface
Public Function QueryCustomDataSetForString(ByVal CustomDataSet As Microsoft.RuleEngine.TypedXmlDocument, ByVal ElementName As String) As String
Dim elLog As New System.Diagnostics.EventLog("Application", Environment.MachineName, "MyRulesInterface")
elLog.WriteEntry("It's working ... ", EventLogEntryType.Information)
elLog.WriteEntry("XML received in Typed Document : " & CustomDataSet.Document.OuterXml, EventLogEntryType.Information)
Dim ntable As NameTable = New NameTable()
Dim cNsMgr As XmlNamespaceManager = New XmlNamespaceManager(ntable)
Dim cdsXML As XmlDocument = DirectCast(CustomDataSet.Document, XmlDocument)
elLog.WriteEntry("XML converted in XMLDocument : " & cdsXML.InnerXml, EventLogEntryType.Information)
Dim value As String = ""
If Not cdsXML.SelectSingleNode("//cds:CustomDataSet/cds:" & ElementName, cNsMgr) Is Nothing Then
value = cdsXML.SelectSingleNode("//cds:CustomDataSet/cds:" & ElementName, cNsMgr).InnerText
value = "NULL"
Catch ex As Exception
elLog.WriteEntry("Exception : " & ex.ToString, EventLogEntryType.Error)
I strong named the assembly, added it to the global assembly cache. I can now see it and reference it in the Microsoft Business Rules Composer.
It doesn't seem to work though. I've tried loads of different tests using the "Test Policy..." function, but it doesn't seem to get called.
I put the Event log statements in as an after thought, but nothing is written to the event log.