logo back up home forward   further reading more topics »

XES - Programmers Guide - nodeSwitch

for information about XES schema see these pages.

Switch

Call different blocks depending on value of variable.

	<xs:complexType name="switchType">
<xs:sequence>
<xs:element name="variable" type="variableType"/>
<xs:element name="case" type="caseType"/>
<xs:element name="default" type="caseType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="caseType">
<xs:sequence>
<xs:element name="constant" type="constantType"/>
<xs:element name="block" type="blockType"/>
</xs:sequence>
</xs:complexType>

It may be better to change this as described here.

It seems to me this requires two node types ‘switch’ and ‘case’ because ‘default’ can be encoded as a special type of ‘case’.

But what should be the structure? I get the impression that Java and C# are defined in a slightly different way? In Java cases are like labels and if a break is not encountered then code execution just carries on past the label, but in C# cases are more like nodes?

Similarly I think we could encode the structure in two different ways (although I think the syntax independent of the semantics)

To explain what I mean I will use the following pseudo code:

switch (variable) {
case 0:
StatementA;
StatementB;
case 1:
StatementC;
default:
StatementD;
StatementE;
}

The first way to encode this would be to put ‘case’ nodes and all statements directly under the ‘switch’ node. If this is done then ‘case’ nodes would not have any child subnodes, this seems to me to give the cases the same sort of structure as labels. This is the way that the program is parsed at the moment (version 0.9).

The second way to encode this would be to put only ‘case’ nodes under the ‘switch’ and to put StatementA and StatementB under case 0, StatementC under case 1, StatementD and StatementE under default.

I seems to me that the second is a better structure and although there is a sort of implication that the statements belong to the cases it does not prevent code from flowing between cases.


metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover Processing XML with Java: A Guide to SAX, DOM, JDOM, JAXP, and TrAX

Other Java books

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to this site, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

cover JBuilder - There is also a free version of Jbuilder at borland website . However its licence conditions are quite restrictive so you may prefer another java IDE.

Can this page be improved?

Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page.

 

progam

I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here:

for xml encoding: http://sourceforge.net/projects/xes/

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2008 Martin John Baker - All rights reserved - privacy policy.