Override Consume

I want to read a XML file of a nework which is produced by GoDiagram.

    public static NetDocument LoadXML(Stream file, String loc)
    {
          NetDocument doc = new  NetDocument();       &nbs p;  
          doc.StartTransaction();
          doc.Clear();
          doc.Location = loc;
          XMLReader reader = new XMLReader();
          reader.AddTransformer(new TransformNode());
          reader.RootObject = doc; 
        AddDocument(loc, doc);          
          reader.Consume(file);
          doc.FinishTransaction("Loaded from file");          
          return doc; 
          }

The problem is that the Consume method here, does not go through the override method in the TransformNode class.
Would you please guide me!

That depends on how you defined TransformNode, and what XML contents you have in the stream/file. Did you set the ElementName and TransformerType properties in your TransformNode constructor?
I don’t know what AddDocument does, but I assume it isn’t relevant to your problem.
Also unrelated to your problem, I assume you have a separate transformer for links, unless you really are only reading in nodes from the XML.

Thanks a lot for your attention.
The XML contents a petri-net diagram data.
The TransformNode looks like processor sample. Moreover, the ElementName and TransformerType are set in constructor.
AddDocument will produce a hashtable.
And, there is a separate transformer for the link.
But I still do not know what is the problem!

What is the first element inside the root element of your XML document? Does it match the TransformNode.ElementName?

The first element in XML document is like this:

and it matches with the ElementName.
But it still has the problem to realize it.

So in your application, TransformNode.ElementName == “pnml”?
The “xmlns” attribute will not affect the choice of transformer. (I assume the duplicate “http://” is a typo or else an unusual naming convention.)
Here’s a simple example, that only reads nodes, no links.
The transformer for a GoBasicNode:
internal class SimpleXmlTransformBasicNode : GoXmlTransformer {
public SimpleXmlTransformBasicNode() {
this.TransformerType = typeof(GoBasicNode);
this.ElementName = “node”;
this.IdAttributeUsedForSharedObjects = true;
}
public override void GenerateAttributes(Object obj) {
base.GenerateAttributes(obj);
GoBasicNode n = (GoBasicNode)obj;
WriteAttrVal(“spot”, n.LabelSpot);
WriteAttrVal(“label”, n.Text);
WriteAttrVal(“loc”, n.Location);
}

public override Object Allocate() {
GoBasicNode n = new GoBasicNode();
// you might want to do other common initialization here
return n;
}
public override void ConsumeAttributes(Object obj) {
base.ConsumeAttributes(obj);
GoBasicNode n = (GoBasicNode)obj;
n.LabelSpot = Int32Attr(“spot”, GoObject.Middle);
n.Text = StringAttr(“label”, “”);
n.Location = PointFAttr(“loc”, new PointF(100, 100));
}
}
The code to use this transformer class:
Stream file = File.Open(…, FileMode.Open);
GoXmlReader r = new GoXmlReader();
r.AddTransformer(new SimpleXmlTransformBasicNode());
r.RootObject = myView.Document;
r.Consume(file);
file.Close();
A sample XML file:




Thank you very much.
I have some codes like your sample, but I will check it again.

This is one example of program output that I want to read it, it is a little bit diffrent than GoDiagram “processor” sample.
I have the above mentioned codes in my read part of program but it still can not open the file. The open just opens a new empty window.
This example has one place like processor node that it has its own special specifications.

-- <net id="0" uniqueID="1286496556" type="http://http://www.nwoods.com/net">
- <name>
<text>Net</text>

<span =“b”> <span =“m”></<span =“t”>name<span =“m”>>

- <comment>
<text />

<span =“b”> <span =“m”></<span =“t”>comment<span =“m”>>

<inputSignals />
<outputSignals />
- <toolspecific tool="XMLEditor">
<placeShowName value="1" />
<placeShowComment value="1" />
<placeShowOutVec value="0" />
<transitionShowName value="1" />
<transitionShowComment value="1" />
<transitionShowCondition value="1" />
<linkShowTiming value="1" />
<commentsShow value="1" />
<includeSubnetXML value="1" />

<span =“b”> <span =“m”></<span =“t”>toolspecific<span =“m”>>

- <arc source="1" target="2">
- <annotation>
<text />

<span =“b”> <span =“m”></<span =“t”>annotation<span =“m”>>

- <graphics>
<position x="176" y="89.5" />
<position x="176" y="130" />
<position x="176" y="145" />

<span =“b”> <span =“m”></<span =“t”>graphics<span =“m”>>

- <label>
- <graphics>
<position x="179.483261" y="116.189346" />

<span =“b”> <span =“m”></<span =“t”>graphics<span =“m”>>

- <toolspecific tool="XMLEditor">
<showTiming value="1" />

<span =“b”> <span =“m”></<span =“t”>toolspecific<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>label<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>arc<span =“m”>>

- <place id="1" uniqueID="1745745459">
- <name>
<text>p1</text>

<span =“b”> <span =“m”></<span =“t”>name<span =“m”>>

- <comment>
<text />

<span =“b”> <span =“m”></<span =“t”>comment<span =“m”>>

- <outputAssignments>
- <initialMarking>
<value>0</value>
- <toolspecific tool="XMLEditor">
<hasToken value="0" />
<isInitialPlace value="0" />
<isFinalPlace value="0" />

<span =“b”> <span =“m”></<span =“t”>toolspecific<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>initialMarking<span =“m”>>

- <label>
- <graphics>
<position x="216" y="62" />

<span =“b”> <span =“m”></<span =“t”>graphics<span =“m”>>

- <toolspecific tool="XMLEditor">
<showName value="1" />
<showComment value="1" />
<showOutVec value="1" />

<span =“b”> <span =“m”></<span =“t”>toolspecific<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>label<span =“m”>>

- <graphics>
<position x="176" y="77" />

<span =“b”> <span =“m”></<span =“t”>graphics<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>outputAssignments<span =“m”>>

- <transition id="2" uniqueID="2045582001">
- <name>
<text>t1</text>

<span =“b”> <span =“m”></<span =“t”>name<span =“m”>>

- <comment>
<text />

<span =“b”> <span =“m”></<span =“t”>comment<span =“m”>>

- <condition>
<text />

<span =“b”> <span =“m”></<span =“t”>condition<span =“m”>>

- <label>
- <graphics>
<position x="315" y="130" />

<span =“b”> <span =“m”></<span =“t”>graphics<span =“m”>>

- <toolspecific tool="XMLEditor">
<showName value="1" />
<showComment value="1" />
<showCondition value="1" />

<span =“b”> <span =“m”></<span =“t”>toolspecific<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>label<span =“m”>>

- <graphics>
<position x="225" y="150" />
<dimension width="151.119781" height="45.2734375" />

<span =“b”> <span =“m”></<span =“t”>graphics<span =“m”>>

- <toolspecific tool="XMLEditor">
<portOrientation value="UpDown" />

<span =“b”> <span =“m”></<span =“t”>toolspecific<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>transition<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>place<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>net<span =“m”>>

<span =“b”> <span =“m”></<span =“t”>pnml<span =“m”>>
Thank you again for your help.