INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Referencing Dynamic XML elements in my Business Rules

Referencing Dynamic XML elements in my Business Rules

(OP)
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="http://mynamespace.com/something/DataSet.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:business="http://mynamespace.com/something/DataSet.xsd" 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="http://mynamespace.com/something/DataSet.xsd">
    <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", "http://mynamespace.com/something/DataSet.xsd")

                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


 

RE: Referencing Dynamic XML elements in my Business Rules

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.
<xsd:element name="CustomDataSet" type="business:ty_custom_xml" />

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close