Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing Dynamic XML elements in my Business Rules

Status
Not open for further replies.

blondebier

Programmer
Jun 19, 2003
142
GB
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 have nothing to say on BizTalk. I can only tell the xsd posted as such. It is not a valid (w3c) schema and won't be apt to valid an instance document. The global xsd:element element does not support cardinal facets.

Try change this:
><xsd:element name="CustomDataSet" type="business:ty_custom_xml" minOccurs="0" maxOccurs="1" />
to this.
[tt]<xsd:element name="CustomDataSet" type="business:ty_custom_xml" />[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top