Trouble consuming XML

I am trying to write code that will load an XML document, transform the data, and apply one of the pre-defined layouts provided with GoDiagram. The code runs without error (as far as I can tell), but I am still getting a blank diagram in my web page. Additional note - I have placed the GoView in a user control and I placed the user control in my web page.

Here is the code from my user control.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("connUSCG_WPM").ConnectionString())
    Dim cmnd As New SqlCommand("sp_GetOrgChartXML", conn)
    cmnd.CommandType = CommandType.StoredProcedure
    cmnd.Parameters.Add("@ID", SqlDbType.Int)
    cmnd.Parameters("@ID").Value = mID
        Dim xmlDoc As New XmlDocument()
        If xmlDoc.HasChildNodes() Then
            GoView1.EnableViewState = True
            Dim r As New GoXmlReader()
            r.AddTransformer(New XMLTransformBasicNode())
            r.AddTransformer(New XMLTransformLink())
            r.RootObject = GoView1.Document
            GoView1.FinishTransaction("load xml source")
        End If
        Dim layout As New GoLayoutLayeredDigraph()
        layout.DirectionOption = GoLayoutDirection.Down
        layout.Document = GoView1.Document
        GoView1.FinishTransaction("layered-digraph autolayout")

    End Try
End Sub

The XMLTransformBasicNode, and XMLTransformLink classes are classes I have written based on the examples provided in the GoSamples. It is interesting that, if I place a break point in the constructor of either XMLTransformBasicNode.vb or XMLTransformLink.vb, the break point is hit…so I know that the constructors are called. However, if I put breakpoints in either XMLTransformBasicNode.ConsumeAttributes or XMLTransformLink.ConsumeAttributes, those subroutines are never called. So I think the problem is at the line “r.Consume(xmlDoc)” in the code above.

I apologize for the long message.
Thank you for any help you can provide.

That looks OK. Are you sure the XML looks right? Does each GoXmlTransformer that you have defined specify the right value for ElementName?

You are amazing.
The elements are named “Scene” and “Link” and I had “scene” and “link” in my transformer code. So, that was the problem.

Thank you for that.

So, now I can see my diagram.
I now have the issue that only one node is being displayed, when I know there are many more nodes than that. I believe I need to implement a ConsumeChild (what a terrible routine name! Tongue) similar to this example from the sample projects:

Public Overrides Sub ConsumeChild(ByVal parent As Object, ByVal child As Object)
MyBase.ConsumeChild(parent, child)
Dim x As GoSubGraph = CType(parent, GoSubGraph)
Dim c As GoObject = Nothing
If TypeOf child Is GoObject Then c = CType(child, GoObject)
End Sub

I will get to work on that and, hopefully, not have to bother you again.

Thanks again. It would have taken me FOREVER to find that problem (if ever)!

Ah, the case-sensitivity of XML strikes again.
ConsumeChild is usually just used when you have XML structured like:
[code] [/code]
In other words, when you have nested XML.

Yes, that is what I have: a nested xml document…it is generated from a recursive SQL function in my database. I am having some trouble getting it to display the information correctly, however. It looks like it is essentially placing all the nodes on top of each other, and I am not sure why. I placed my ConsumeChild routines in XMLTransformBasicNode.vb and XMLTransformLink.vb and, it seems to be adding all the nodes.

Another question: If a node has multiple children, does it need to have a different port for each link to each of its children? Or, can a parent have one port from which it links to, for example, four children?

Thanks again for all your help.

Are you generating a “tree” diagram? If so, your override of ConsumeChild should Add the resulting node to your document, not to the “parent” node. I guess you have separate elements, so your ConsumeChild doesn’t have to create the link and connect the nodes and then Add the link to the document. In fact, in this case, you probably don’t want to be using GoSubGraph at all. Look at the TreeApp sample for an example of what I mean.

Also, if you are producing a tree-structured diagram, you might find the GoLayoutTree algorithm better than GoLayoutLayeredDigraph, since GoLayoutTree has all kinds of features that are naturally specific to trees.
Alternatively, if you really do need to use GoSubGraph or GoSubGraphBase, then you need to recursively apply the layout to the contents of the GoSubGraph. This is documented in the Layout User Guide, and I think is demonstrated in SubGraphApp.
Yes, you can have any number of links connected at a single port.

I can use a tree diagram. I think that, in your samples, I saw it mentioned that I could specify the “orientation” of the tree…either parent to the left and children to the right, or parent on top and children below…is that correct?

I am implementing an org chart, so I would like the default layout to be:
| |


But offer the user the ability to switch to a layout like:

I currently have the diagram showing nodes with titles (YEAH!). They are in the “Parent to the right and children to the left” orientation, and I don’t have the links working yet but…this is real progress.

thanks again.

If you use GoLayoutTree, that’s easy to control The documentation shows you what parameters will get you the results you want.