Creating SubGraphs when consuming XML

I am having trouble creating a subgraph for a node in a flowchart diagram that is created from XML. I am using the GoLayoutLayeredDigraph to create flow charts from XML source. It is all working pretty well but, now I am trying to create subgraphs that are attached to certain nodes. Here is what I would like to have:

and here is what I am getting:

Here is the code I have in my XMLTransformFlowChartNode.vb code:
Public Overrides Sub ConsumeChild(ByVal parent As Object, ByVal child As Object)
Dim p As FlowNode = CType(parent, FlowNode)
If p.HasSubGraph Then
Dim sg As GoSubGraph = p.FindChild(“subGraph”) 'Has subgraph been added yet?
If sg Is Nothing Then 'If not, then add it
sg = New GoSubGraph()
p.Add(sg)
p.AddChildName(“subGraph”, sg)
End If
MyBase.ConsumeChild(sg, child)
Dim c As FlowNode = CType(child, FlowNode)

        Dim doc As GoDocument = CType(Me.Reader.RootObject, GoDocument)
        doc.Add(c)
    Else
        MyBase.ConsumeChild(parent, child)
        Dim c As FlowNode = CType(child, FlowNode)
        Dim doc As GoDocument = CType(Me.Reader.RootObject, GoDocument)
        doc.Add(c)
    End If
End Sub

The code runs without error and it appears that the nodes representing “a” and “b” from the illustrations above are being added to the subgraph. But when the diagram is drawn, they appear as normal children of the node that contains the subgraph.
Is this a Layer issue? Or do I misunderstand the subgraph functionality all-together?

Thanks for any help you can provide.
roger

No, it appears your code is adding those subgraph’s child nodes to the document, not to the subgraph itself.

If you have nested XML elements representing nodes, and if you are using GoSubGraph to group those nodes together, you have to add all of them to the GoSubGraph. Adding them to the GoDocument just makes them top-level objects in the document's default layer.

Thanks for your response.

I changed the ConsumeChild code to this:
Public Overrides Sub ConsumeChild(ByVal parent As Object, ByVal child As Object)
Dim p As FlowNode = CType(parent, FlowNode)
If p.HasSubGraph Then
Dim sg As GoSubGraph = p.FindChild(“subGraph”)
If sg Is Nothing Then
sg = New GoSubGraph()
p.Add(sg)
p.AddChildName(“subGraph”, sg)
End If
MyBase.ConsumeChild(sg, child)
Dim c As FlowNode = CType(child, FlowNode)
sg.Add©
Else
MyBase.ConsumeChild(parent, child)
Dim c As FlowNode = CType(child, FlowNode)
Dim doc As GoDocument = CType(Me.Reader.RootObject, GoDocument)
doc.Add©
End If
End Sub

…but, when the line “sg.Add©” runs, I get an error.
“Cannot add an object to a group when it is already part of a document or view”.

I don’t understand why I get this error when trying to add to the subgraph but, I don’t get it when I try to add a normal node to the doc.
hmmmmmm.

What does “MyBase.ConsumeChild” do? Does it add “child” to the document?

MyBase.ConsumeChild is calling GoXMLTransformer.ConsumeChild. I have created a class that inherits GoXMLTransformer in order to create the flowchart’s nodes, and the code I included is the override of the ConsumeChild function. The class is “XMLTransformFlowChartNode”

Do you think I should create a class that inherits GoXMLTransformer, and creates a SubGraph object, and then consumes its children? Like “XMLTransformFlowSubGraph”, for instance?

I would have to re-work my XML source…but that might be the way to go?

Thanks for your help.

No, I don’t think you need to restructure your transformers, but I’m not sure, because I’m not sure I understand what you want to do.

What I was asking about is when the child FlowNode was added to the document, hence causing the error you get when trying to add that same node to a subgraph.

Thanks for your reply.

I experimented with creating a new transformer that would create a GoSubGraph, and then I modified my XML to create a element that could then be consumed. But, that didn’t work because the subgraph is just added to the document, and not added to the node so it could then contain the child nodes.

So, I am going back to my original approach. I will try to figure out when the child FlowNode is being added to the document and then try to make it add the child nodes in question (a & b from my original diagrams) to the subGraph object, and not to the document object.

I hope that is right! Smile

I will continue playing with it.

Thanks for your help, and have a great weekend.
roger.