SWSL is serialized in XML using RuleML. RuleML-style serialization of SWSL enables interoperation with other XML applications for rules and provides an encoding for transporting SWSL-Rules via the SOAP infrastructure of Web services.

RuleML integrates various rule paradigms via common set of concepts and defines a family of rule-based, Web-enabled sublanguages with various degrees of expressiveness. This section applies the RuleML approach to serialization of SWSL. This is done mostly by reusing and sometimes extending the existing RuleML sublanguages. In addition, a new sublanguage for the serialization of HiLog is developed.

Serialization of the presentation syntax of SWSL-Rules amounts to construction of explicit parse trees and then representing these trees linearly as XML markup that is compliant with XML Schema of the appropriate RuleML sublanguages. Starting with Version 0.89, the XML Schema specification of RuleML supports SWSL-Rules.

Serialization of SWSL-FOL does not require any new constructs, and it is done by repurposing existing RuleML features. Serialization of SWSL-FOL is discussed at the end of this section, in Section 4.5.

Conceptually, RuleML models XML trees as objects and thus divides all XML tags into class descriptors, called type tags, and property descriptors, called role tags. This conceptual object-oriented model implies that type tags and role tags must alternate, which is known as striped XML syntax. For instance, in F-logic and RDF, classes can have properties, which point to classes, which have properties that point to classes, etc. Similarly, in the striped XML syntax, a type tag has role tags as subelements, whose children are again type tags, etc. When the role of a subelement is clear from the context, its tag may be skipped for brevity, as in RDF's StripeSkipping.

4.1 Serialization of the HiLog Layer

HiLog terms. The HiLog serialization uses the type tag Hterm for HiLog terms, Con for constants, and Var for variables. Since HiLog allows arbitrary terms to be used in the position of predicate and function symbols, the RuleML serialization allows not only constants but also variables and Hterms under the op role tag . The following illustrates the main aspects of the HiLog serialization.

HiLog atomic formulas. Since any HiLog term is also a HiLog atomic formula, the RuleML serialization for these formulas is the same as for HiLog terms. The following example shows an encoding of a query, which uses the Query element of RuleML:

	?- q(?X) and ?X.
      
	<Query>
	   <And>
	      <Hterm>
	         <op><Con>q</Con></op>
	         <Var>X</Var>
	      </Hterm>
	      <Var>X</Var>
	   </And>
	<Query>
      

Another interesting example is a HiLog rule

	call(?X) :- ?X.
      

which is a logical definition of the meta-predicate call/1 in Prolog. This is translated using the RuleML tags Implies, head, and body, as follows:

	<Implies>
	   <head>
	      <Hterm>
	         <op><Con>call</Con></op>
	         <Var>X</Var>
	      </Hterm>
	   </head>
	   <body>
	      <Var>X</Var>
	   </body>
	</Implies>
      

4.2 Serialization of Explicit Equality

The explicit equality predicate :=: is serialized using the RuleML's element Equal. For example,

	f(a,?X):=:g(?Y,b) :- p(?X,?Y).
      

is serialized as

	<Implies>
	   <head>
	      <Equal>
	         <Hterm>
	            <op><Con>f</Con></op>
	            <Con>a</Con>
	            <Var>X</Var>
	         </Hterm>
	         <Hterm>
	            <op><Con>g</Con></op>
	            <Var>Y</Var>
	            <Con>b</Con>
	         </Hterm>
	      </Equal>
	   </head>
	   <body>
	      <Hterm>
	         <op><Con>p</Con></op>
	         <Var>X</Var>
	         <Var>Y</Var>
	      </Hterm>
	   </body>
	</Implies>
      

4.3 Serialization of the Frames Layer

To serialize the Frames layer of SWSL-Rules we need to show the serialization of the various molecules and path expressions introduced by F-logic.

Molecules. The serialization of molecules uses slotted atoms, which have an oid but often do not have an op. The overall structure of F-logic molecules (except for class membership and subclassing) is as follows:

	Atom ::= oid op? slot*
      

Nested molecules. Direct serialization of nested molecules is not currently supported. Instead, they must first be broken into conjunctions of non-nested molecules and then serialized.

Slot access and path expressions. Serialization of slot access uses the RuleML Get primitive. Serialization of path expressions is supported via the polyadic RuleML SlotProd element. For example, room.ceiling.color becomes the following:

        <Get>
           <oid><Con>room</Con></oid>
           <SlotProd><Con>ceiling</Con><Con>color</Con></SlotProd>
        </Get> 
      

4.4 Serialization of Reification

SWSL-Rules supports reification of F-logic molecules, formulas that can occur in the head or the body of a rule, and of the rules themselves. The only restriction is that explicit quantifiers cannot occur under the scope of the reification operator. The main idea behind RuleML serialization of such statements is that the corresponding serialized statement must be embedded within a Reify element.

To illustrate, consider the following molecule:

	a[b -> ${p(X[foo -> bar])}] 
      

Since the reified statement (p(X[foo -> bar]) is an Hterm, this tag becomes the child of the Reify element.

	<Hterm>
	   <oid><Con>a</Con></oid>
	   <slot>
	      <Con>b</Con>
	      <Reify>
	         <Hterm>
	            <op><Con>p</Con></op>
	            <Hterm>
	               <oid><Var>X</Var></oid>
	               <slot><Con>foo</Con><Con>bar</Con></slot>
	            </Hterm>
	         </Hterm>
	      </Reify>
	   </slot>
	</Hterm>
      

The following example illustrates serialization of a reified rule.

	john[believes -> ${p(?X) implies q(?X)}].
      

The corresponding serialization is shown below. Since the top-level tag of a rule is Implies, this tag becomes the child of the Reify element.

	<Hterm>
	   <oid>john</oid>
	   <slot>
	      <Con>believes</Con>
	      <Reify>
	         <Implies>
	            <body>
	               <Hterm>
	                  <op><Con>p</Con></op>
	                  <Var>X</Var>
	               </Hterm>
	            </body>
	            <head>
	               <Hterm>
	                  <op><Con>q</Con></op>
	                  <Var>X</Var>
	               </Hterm>
	            </head>
	         </Implies>
	      </Reify>
	   </slot>
	</Hterm>
      

4.5 Serialization of SWSL-FOL

Serialization of SWSL-FOL reuses the existing FOL RuleML sublanguage. The serialization is accomplished through the following rules: