blondebier
Programmer
Hi Guys,
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:schema targetNamespace=" xmlns:xsd=" xmlns:business=" elementFormDefault="qualified">
<xsd:element name="CustomDataSet" type="business:ty_custom_xml" minOccurs="0" maxOccurs="1" />
<xsd:complexType name="ty_custom_xml">
<xsd:sequence>
<xsd:any namespace="##any" processContents="skip" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
The XML document that this relates to would look something like :
<CustomDataSet xmlns=" <SomeInfo>AK234</SomeInfo>
<SomethingElse>125.00</SomethingElse>
<SomethingDerived>16982</SomethingDerived>
</CustomDataSet>
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 :
Imports System
Imports System.Xml
Imports Microsoft.RuleEngine
Namespace MyNameSpace
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)
Try
Dim ntable As NameTable = New NameTable()
Dim cNsMgr As XmlNamespaceManager = New XmlNamespaceManager(ntable)
cNsMgr.AddNamespace("cds", "
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
Else
value = "NULL"
End If
Return value
Catch ex As Exception
elLog.WriteEntry("Exception : " & ex.ToString, EventLogEntryType.Error)
Throw ex
Finally
elLog.Dispose()
End Try
End Function
End Class
End Namespace
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.
Any ideas?
Cheers,
Blondebier
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:schema targetNamespace=" xmlns:xsd=" xmlns:business=" elementFormDefault="qualified">
<xsd:element name="CustomDataSet" type="business:ty_custom_xml" minOccurs="0" maxOccurs="1" />
<xsd:complexType name="ty_custom_xml">
<xsd:sequence>
<xsd:any namespace="##any" processContents="skip" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
The XML document that this relates to would look something like :
<CustomDataSet xmlns=" <SomeInfo>AK234</SomeInfo>
<SomethingElse>125.00</SomethingElse>
<SomethingDerived>16982</SomethingDerived>
</CustomDataSet>
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 :
Imports System
Imports System.Xml
Imports Microsoft.RuleEngine
Namespace MyNameSpace
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)
Try
Dim ntable As NameTable = New NameTable()
Dim cNsMgr As XmlNamespaceManager = New XmlNamespaceManager(ntable)
cNsMgr.AddNamespace("cds", "
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
Else
value = "NULL"
End If
Return value
Catch ex As Exception
elLog.WriteEntry("Exception : " & ex.ToString, EventLogEntryType.Error)
Throw ex
Finally
elLog.Dispose()
End Try
End Function
End Class
End Namespace
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.
Any ideas?
Cheers,
Blondebier