Page 166 - The Ultimate Palm Robot
P. 166

Color profile: Generic CMYK printer profile
           Composite  Default screen
                                                          Bots /The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 6






                                                      Chapter 6  The Palm Robot Programmer (PRP)     149



                                      We should emphasize that this section is intended for those of you who are
                                    already programmers and know something about Java, Extensible Markup
                                    Language (XML), and Extensible Stylesheet Language Transformations
                                    (XSLT).


                         How the PRP Converts a Program to Source Language
                                    If you built the example program earlier in this chapter and saved it to your
                                    system, you can navigate to that file now and have a look at it. (If you didn’t
                                    create the sample program earlier, go back and do that now.) When you con-
                                    vert a program to a source file, two files are created. The first file contains the
                                    translated source code for the program. The other file contains an XML repre-
                                    sentation of the program.
                                      If you have translated a program, navigate to the directory that contains
                                    the source file. In that directory, you should find a file with the same name but
                                    with a .xml extension. Open the XML file in a text editor. Here is the XML file
                                    for the program we created at the beginning of this chapter:


                                   <?xml version="1.0"?>
                                   <PalmRobotProgram>
                                   <Main programName="ToFro">
                                   <ServoStart servoNumber="1" servoDirection="1"/>
                                   <ServoStart servoNumber="2" servoDirection="-1"/>
                                   <Sleep sleepSeconds="2"/>
                                   <ServoStart servoNumber="1" servoDirection="-1"/>
                                   <ServoStart servoNumber="2" servoDirection="1"/>
                                   <Sleep sleepSeconds="2"/>
                                   <ServoStop servoNumber="1"/>
                                   <ServoStop servoNumber="2"/>
                                   </Main>
                                   </PalmRobotProgram>

                                      When the PRP translates a program, it creates an XMLrepresentation of the
                                    program. All of the program constructs and icons that you create in the PRP
                                    workspace are stored in this XMLfile. Next, the PRP uses XSLT to translate the
                                    XMLinto source code. In simple terms, XSLT provides a standard way to use a
                                    style sheet to transform XML into some other representation.

                         How to Write Your Own Converter
                                    To create your own converter, you will need to be able to create a relatively
                                    simple Java class and a more complicated XSLT file. After installing these files






           P:\010Comp\Bots\880-6\ch06.vp
           Monday, May 12, 2003 1:06:27 PM
   161   162   163   164   165   166   167   168   169   170   171