Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml script language design question 1

Status
Not open for further replies.

sergivs

Programmer
May 18, 2007
6
US
Hi all,

First, some some background information.

I have written a Java application that runs XML-based scripts with relatively simple syntax. The syntax is defined in a schema, so it's possible to a) generate Java binding classes for the application and b) use an editor with validation and code completion.

The scripts are becoming longer and more complex; they could be greatly simplified if there were support for procedures. It's probably possible to generate complex scripts using XSLT, but I have a very superficial knowledge of it and this approach seems too cumbersome, so I'll probably go with procedures. They would be defined and called in the same script file, I imagine.

I would like to define as much of the syntax as possible in the schema and do as little as possible additional validation on the application interpreter level; additionally, I'd like to keep the syntax simple.

The problem is to choose the right syntax and scope for the procedure arguments.

Now, the question:

Is there any way to define the relationship between procedure arguments and procedure calls in the schema, using keyref, idref or anything else?

For example (not the simplest syntax):

<ProcedureDef name="foo">
<ArgumentDef name="fooarg1"/>
<ArgumentDef name="fooarg2"/>
<DoStuff>
....
<DoStuff/>
</Procedure>

<ProcedureDef name="bar">
<DoStuff>
....
<DoStuff/>
</Procedure>

<Call procedureName="foo">
<Argument name="fooarg1" value="1"/>
<Argument name="fooarg2" value="2"/>
</Call>

<Call procedureName="foo">
<Argument name="fooarg1" value="3"/>
<Argument name="fooarg2" value="4"/>
</Call>

<Call procedureName="bar"/>

Many thanks in advance for any advice.
 
As I understand it, there involves quite a number of constraints:

[1] For every ProcedureDef, the name attribute is unique.
[2] For every Call, the procedureName attribute must take on a value existing as the name attribute of some ProcedureDef.
[3] For every ProcedureDef, the ArgumentDef's name attribute must be unique and not duplicated.
[4] For every Call, the Argument's name attribute must be unique and not duplicated.
[5] For every Call, it's Arguments' name attribute must correspond exactly to the corresponding procedureDef's ArgumentDef.

Within the wxsl, [1]-[4] can be handled. [5] I don't think it can be handled as such within wxsl at present.

This is how you handle [1]-[4]. (The "root" is the parent of the block shown.)
[tt]
<xs:schema xmlns:xs=" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="root" type="rootType">
<xs:key name="pk_procedure">
<xs:selector xpath=".//ProcedureDef" />
<xs:field xpath="@name" />
</xs:key>
<xs:keyref name="kr_call_procedure" refer="pk_procedure">
<xs:selector xpath=".//Call" />
<xs:field xpath="@procedureName" />
</xs:keyref>
</xs:element>

<xs:complexType name="rootType">
<xs:sequence>
<xs:element ref="ProcedureDef" minOccurs="0" maxOccurs="unbounded" />
<xs:element ref="Call" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>

<xs:element name="ProcedureDef" type="ProcedureDefType">
<xs:key name="kp_procedure_argument">
<xs:selector xpath=".//ArgumentDef" />
<xs:field xpath="@name" />
</xs:key>
</xs:element>

<xs:complexType name="ProcedureDefType">
<xs:sequence>
<xs:element name="ArgumentDef" type="ArgumentDefType" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="DoStuff" type="xs:string" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>

<xs:complexType name="ArgumentDefType">
<xs:attribute name="name" type="xs:string" />
</xs:complexType>

<xs:element name="Call" type="CallType">
<xs:key name="kp_call_argument">
<xs:selector xpath=".//Argument" />
<xs:field xpath="@name" />
</xs:key>
</xs:element>

<xs:complexType name="CallType">
<xs:sequence>
<xs:element name="Argument" type="ArgumentType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="procedureName" type="xs:string" />
</xs:complexType>

<xs:complexType name="ArgumentType">
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="value" type="xs:integer" />
</xs:complexType>

</xs:schema>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top