Loading ...
Sorry, an error occurred while loading the content.

Can we use XPath (was Re: [pcgen-xml] First pass at an XML choose tag)

Expand Messages
  • Frugal
    This started as a coherant example by example response, then I went off on a tangent so I have changed the tag line. ...
    Message 1 of 15 , May 10, 2004
    • 0 Attachment
      This started as a coherant example by example response, then I went off on
      a tangent so I have changed the tag line.

      <quote who="Jenni A. Merrifield">
      > After looking through Frugal's "playing" XML file, I gave some thought
      > to
      > the issue of how to do choices. The following is what I came up with as a
      > first stab at it. I expect it will needs some revision, but I figured it
      > was
      > a place to start. :-)

      Sorry that I have been so long to repond, a combination of work, baby and
      life got in the way of real coding ;O)

      > <!-- non-normative examples of the choose and choice tags -->
      > <choose id="SomeFeat" num="1" >

      So this ia a choose block with the name "SomeFeat" that is to ask the user
      for a single object from the options below.

      > <!-- Choice of any feat -->
      > <choice kind="feat" />

      Hmmm... We do not have a "feat" kind. Feats are just entities that are
      generally given ids starting "feat.".

      we could either:

      1 - Make feats a concrete entity subclass, which I personally do not like
      as it ties the concept of feats into the data rather than the application.

      2 - use <choice kind="entity" type="feat"/> to select all entities with
      the "feat" type.

      3 - use <choice type="feat" /> to select all objects in the data with the
      "feat" type.


      > <!-- Choice of any feat of type="general" -->
      > <choice kind="feat" type="general" />

      Bugger, I have just moved the "feat" from kind to type... So we are going
      to need someway to have multiple types, which we are going to need anyway
      for some complex stuff.

      I keep coming back to doing this with a query language:

      <choice select="//entity[types/type='feat' and types/type='fighter']" />

      Would it just be easier to write an XPath parser for java datatypes ;O)

      ... actually now that I stop for a moment; is that really such a daft
      idea? If we assume that this low level XML maps directly onto java classes
      then why can we not use XPath? We have the complete BNF of the XPath
      syntax available so writing a parser should not be too difficult. The only
      issue would be treating the objects as data types for the Java API and
      trees for the XPath API. i.e. "entity[types/type='feat'" needs to have
      'types' available as a child of 'entity' and 'type' available as a subnode
      of 'types' even if the internal data structure was

      class Entity {
      List types;
      };

      The more I think about this the more I feel that a query language will be
      more use than trying to cobble something together using a small series of
      tags with attributes.

      If we were to extend this idea we could also reference the character.

      <... select="/character/entities/entity[types/type='feat' and
      types/type='fighter']" />

      To select all the Fighter feats the character currently has associated
      with them.

      If we parsed the query language into an internal structure we could even
      use different external representations:

      <choice lang="xpath" select="//entity[types/type='feat' and
      types/type='fighter']" />

      <choice lang="sql" select="select * from entity where type='feat' and
      type='fighter'" />

      Somebody please tell me that Rowan's three hours of collicy screaming last
      night has fused both of my brain cells before I convince myself that this
      is a good idea...

      --
      regards,
      Frugal
      -OS Chimp
    • Frugal
      ... Having had a quick look at the XPath stuff that comes with Xerces and Xalan it would appear that it only works with DOM. Jaxen on the
      Message 2 of 15 , May 10, 2004
      • 0 Attachment
        <quote who="Frugal">

        > The only
        > issue would be treating the objects as data types for the Java API and
        > trees for the XPath API. i.e. "entity[types/type='feat'" needs to have
        > 'types' available as a child of 'entity' and 'type' available as a subnode
        > of 'types' even if the internal data structure was
        >
        > class Entity {
        > List types;
        > };

        Having had a quick look at the XPath stuff that comes with Xerces and
        Xalan it would appear that it only works with DOM.

        Jaxen on the other hand will let you use any document model you want. You
        just need to implement the Navigator interface for your model. This has a
        function for each axis:

        public Iterator getChildAxisIterator(Object contextNode)
        throws UnsupportedAxisException

        where context node could be an object that details where we are in our
        virtual tree (i.e. a list of context nodes from root leading to this one).

        So the path stack for /entities/entity[12]/types/type[1] would look
        something like:

        [0] = DocumentRootNode { }
        [1] = RootNode { }
        [2] = ArrayNode { Array array=entityList };
        [3] = ArrayEntryNode { Entity entity=foo; position=12 }
        [4] = ArrayNode { Array array=bar }
        [5] = ArrayEntryNode { Object object=froboz; position=1 }

        Then we can navigate around our tree with a little help from the data
        structures. i.e. an Entity class would have to know how to respond to a
        request for a "types" child, but we can apply an interface to our classes
        to help navigate them, or use a Beans based approach to interrogating the
        contents of an object (e.g. an Entity).

        ...Waits with baited breath for Keith to explain why this is a bad idea ;O)

        --
        regards,
        Frugal
        -OS Chimp
      • andargor
        ... and ... want. You ... has a ... our ... this one). ... data ... to a ... classes ... interrogating the ... idea ;O) ... I m actually using XPath quite
        Message 3 of 15 , May 10, 2004
        • 0 Attachment
          --- In pcgen-xml@yahoogroups.com, "Frugal" <frugal@p...> wrote:
          > <quote who="Frugal">

          > Having had a quick look at the XPath stuff that comes with Xerces
          and
          > Xalan it would appear that it only works with DOM.
          >
          > Jaxen on the other hand will let you use any document model you
          want. You
          > just need to implement the Navigator interface for your model. This
          has a
          > function for each axis:
          >
          > public Iterator getChildAxisIterator(Object contextNode)
          > throws UnsupportedAxisException
          >
          > where context node could be an object that details where we are in
          our
          > virtual tree (i.e. a list of context nodes from root leading to
          this one).
          >
          > So the path stack for /entities/entity[12]/types/type[1] would look
          > something like:
          >
          > [0] = DocumentRootNode { }
          > [1] = RootNode { }
          > [2] = ArrayNode { Array array=entityList };
          > [3] = ArrayEntryNode { Entity entity=foo; position=12 }
          > [4] = ArrayNode { Array array=bar }
          > [5] = ArrayEntryNode { Object object=froboz; position=1 }
          >
          > Then we can navigate around our tree with a little help from the
          data
          > structures. i.e. an Entity class would have to know how to respond
          to a
          > request for a "types" child, but we can apply an interface to our
          classes
          > to help navigate them, or use a Beans based approach to
          interrogating the
          > contents of an object (e.g. an Entity).
          >
          > ...Waits with baited breath for Keith to explain why this is a bad
          idea ;O)
          >
          > --
          > regards,
          > Frugal
          > -OS Chimp

          I'm actually using XPath quite extensively in my experiments. I am
          surprised that you would need DOM.

          For example, I'm using libxml2 (I'm doing this in C++) and it does
          not require DOM nor SAX, and it's damn fast. Portable too.

          Anyway, I feel that XPath is the way to go, since you can change the
          XML format somewhat without having to recode your serach functions.
          It's very flexible.

          I'm toying with SpiderMonkey (Javascript engine, has a Java
          couterpart named Rhino), libxml2 and an "object" engine in C++.

          I'm in my 6th iteration of how to handle all this, so that's why I
          haven't posted anything yet. But the direction I'm goind in is that
          everything is an object, be it a stat, an ability (such as a class
          ability or a feat), or whatever. Class levels, for example, are just
          containers for objects.

          Andargor
        • Frugal
          ... There are various XPth implementations, the Xerces/Xalan combo only uses DOM for XPath queries as it is designed for XSLT only, and
          Message 4 of 15 , May 10, 2004
          • 0 Attachment
            <quote who="andargor">
            > I'm actually using XPath quite extensively in my experiments. I am
            > surprised that you would need DOM.
            >
            > For example, I'm using libxml2 (I'm doing this in C++) and it does
            > not require DOM nor SAX, and it's damn fast. Portable too.

            There are various XPth implementations, the Xerces/Xalan combo only uses
            DOM for XPath queries as it is designed for XSLT only, and thus needs a
            tree in memory.

            > I'm in my 6th iteration of how to handle all this, so that's why I
            > haven't posted anything yet. But the direction I'm goind in is that
            > everything is an object, be it a stat, an ability (such as a class
            > ability or a feat), or whatever. Class levels, for example, are just
            > containers for objects.

            How soon do you think you will have something you can show off ? I am
            curious to see what some one else has come up with.

            --
            regards,
            Frugal
            -OS Chimp
          • andargor
            ... Yeah, libxml2 uses it s own tree structure (a linked list, really) for XPath and XSLT. ... I m working on it :P I m always saying next week or so, then I
            Message 5 of 15 , May 10, 2004
            • 0 Attachment
              --- In pcgen-xml@yahoogroups.com, "Frugal" <frugal@p...> wrote:

              > There are various XPth implementations, the Xerces/Xalan combo only uses
              > DOM for XPath queries as it is designed for XSLT only, and thus needs a
              > tree in memory.

              Yeah, libxml2 uses it's own tree structure (a linked list, really) for
              XPath and XSLT.

              > How soon do you think you will have something you can show off ? I am
              > curious to see what some one else has come up with.
              >
              > --
              > regards,
              > Frugal
              > -OS Chimp

              I'm working on it :P

              I'm always saying next week or so, then I scrap everything and start
              over :) I'm getting a handle on the spidermonkey engine and I think
              the current approach is good, so I'm gonna say next week for basic
              stuff. The gf is going to her folks weekend after next, so I'll have
              some "quality" coding time. :)

              Andargor
            • andargor
              ... Just spotted this thread in d20-xml, and it s very similar to what I m trying to do: http://games.groups.yahoo.com/group/d20-xml/message/2180 Andargor
              Message 6 of 15 , May 11, 2004
              • 0 Attachment
                --- In pcgen-xml@yahoogroups.com, "Frugal" <frugal@p...> wrote:
                > <quote who="andargor">

                > > I'm in my 6th iteration of how to handle all this, so that's why I
                > > haven't posted anything yet. But the direction I'm goind in is that
                > > everything is an object, be it a stat, an ability (such as a class
                > > ability or a feat), or whatever. Class levels, for example, are just
                > > containers for objects.
                >
                > How soon do you think you will have something you can show off ? I am
                > curious to see what some one else has come up with.
                >
                > --
                > regards,
                > Frugal
                > -OS Chimp

                Just spotted this thread in d20-xml, and it's very similar to what I'm
                trying to do:

                http://games.groups.yahoo.com/group/d20-xml/message/2180

                Andargor
              • Frugal
                ... I wonder why I never receive any emails from the D20 list even though I am subscribed... I have been checking out the competition
                Message 7 of 15 , May 13, 2004
                • 0 Attachment
                  <quote who="andargor">
                  > Just spotted this thread in d20-xml, and it's very similar to what I'm
                  > trying to do:
                  >
                  > http://games.groups.yahoo.com/group/d20-xml/message/2180

                  I wonder why I never receive any emails from the D20 list even though I am
                  subscribed...

                  I have been checking out the competition and I noticed that
                  RolePlayingMaster uses javascript for all of it's data. the 'expression'
                  entry for Ambidexterity looks like:

                  function OnCalcWeapon( obj )
                  {
                  if( obj.Attack.Style == 4 ) // Two weapon
                  {
                  if( obj.OffHand )
                  {
                  obj.ToHitBonus += 4;
                  obj.Mods.addMod( "Attack@Ambidexterity", 4, true );
                  }
                  }
                  }

                  and Greater Weapon Focus looks like:

                  function OnCalcWeapon( obj )
                  {
                  var weap = obj;
                  var c = weap.Attack.Creature;
                  var feat = "Greater Weapon Focus: " + weap.ProficiencyName;

                  if( containsStr( c.V_feats, feat, true ) && (weap.doneFocus == NULL) )
                  {
                  weap.doneFocus = true;
                  weap.ToHitBonus += 1;
                  weap.Mods.addMod( "Attack@Greater Weapon Focus", 1, true );
                  }
                  }

                  function OnCreate( obj )
                  {
                  selectFeatItem( "ITEMS_WEAPONS_NAT_ALL", "Select Focus Weapon" );
                  }

                  It is interesting to note that the dialog that pops up for Greter Weapon
                  Focus does not restrict the selection to the weapons you have Weapon Focus
                  for.

                  Out of all of the character generators I have looked at only RedBlade does
                  this, and that is because in the feat editor it has a "use Weapon Focus
                  Feats" check box, everything else just displays the full list of weapons.
                  PCGen appears to be the only editor that tries to restrict the users
                  choices to the correct set...

                  --
                  regards,
                  Frugal
                  -OS Chimp
                • andargor
                  ... what I m ... though I am ... the expression ... (snip) ... Weapon ... Weapon Focus ... RedBlade does ... Focus ... weapons. ... Yes, and I agree with the
                  Message 8 of 15 , May 13, 2004
                  • 0 Attachment
                    --- In pcgen-xml@yahoogroups.com, "Frugal" <frugal@p...> wrote:
                    >
                    > <quote who="andargor">
                    > > Just spotted this thread in d20-xml, and it's very similar to
                    what I'm
                    > > trying to do:
                    > >
                    > > http://games.groups.yahoo.com/group/d20-xml/message/2180
                    >
                    > I wonder why I never receive any emails from the D20 list even
                    though I am
                    > subscribed...
                    >
                    > I have been checking out the competition and I noticed that
                    > RolePlayingMaster uses javascript for all of it's data.
                    the 'expression'
                    > entry for Ambidexterity looks like:
                    >

                    (snip)

                    > It is interesting to note that the dialog that pops up for Greter
                    Weapon
                    > Focus does not restrict the selection to the weapons you have
                    Weapon Focus
                    > for.
                    >
                    > Out of all of the character generators I have looked at only
                    RedBlade does
                    > this, and that is because in the feat editor it has a "use Weapon
                    Focus
                    > Feats" check box, everything else just displays the full list of
                    weapons.
                    > PCGen appears to be the only editor that tries to restrict the users
                    > choices to the correct set...
                    >
                    > --
                    > regards,
                    > Frugal
                    > -OS Chimp

                    Yes, and I agree with the method PCGen uses. Restricting the choices
                    means following the rules and making character generation that much
                    easier for the user.

                    I had tried something similar to this, with XML just
                    being "descriptions" and attached JS code for "behavior".

                    The basic problem is the push and pull model: you retrieve values
                    from other objects and you set values for other objects. This
                    generated horrendous dependency issues, and you have to have several
                    calculation passes to get everything right.

                    What I'm aiming for right now is a completely "pull" model: values
                    are only retrieved from other objects. If any values are set, they
                    stay internal to the object. So a value can be calculated simply by
                    following dependencies. E.g.: evaluate StrMod -> get Str score ->
                    return (Str score - 10)/2

                    I "attach" bonus objects to, say, Str. So when I get Str, it goes
                    through the bonus objects before returning a value.

                    When, say, a feat is added to a character, the feat is an object
                    containing other objects, and they just get inserted in the
                    calculation. Same with classes, races, whatever. The distinction
                    between feat, class, special ability disappears on the surface, and
                    remains inside the object.

                    I'm trying to make objects as self-contained as possible, except for
                    values of other objects. I'm avoiding globals entirely.

                    Anyway, I'm still working on it. Crossing my fingers for next
                    weekend. Haven't coded a line since Sunday... :(

                    Andargor
                  • andargor
                    Hi all, I coded up a little demo to illustrate the advantages of using independent XML objects for character generators. It s a little too large to be put in
                    Message 9 of 15 , May 25, 2004
                    • 0 Attachment
                      Hi all,

                      I coded up a little demo to illustrate the advantages of using
                      independent XML objects for character generators.

                      It's a little too large to be put in the Files section (1.5MB), so
                      it's on my site:

                      http://www.andargor.com/files/panther-demo.zip

                      - Unzip to any directory
                      - Read the README for the explanation on the approach
                      - Execute panther.exe for a sample character

                      I'd love to hear your comments,

                      Andargor
                    • merton_monk
                      I like your implementation. Your xml is easily readible and I like how you abstracted the rules into system.xml. Just from glancing at how you constructed
                      Message 10 of 15 , May 26, 2004
                      • 0 Attachment
                        I like your implementation. Your xml is easily readible and I like
                        how you abstracted the 'rules' into system.xml.

                        Just from glancing at how you constructed your class.xml, I wonder if
                        you could create a class-template, since it appears that a lot of the
                        classes repeat a lot of the same information with only subtle
                        changes. e.g.


                        <object>
                        <category>level</category>
                        <name>Cleric Skill Points 3</name>
                        <classname>Cleric</classname>
                        <classlevel>3</classlevel>
                        <value>2</value>
                        <targets>
                        <target>
                        <category>level</category>
                        <name>Cleric Skill
                        Points</name>
                        </target>
                        <target>
                        <category>skill</category>
                        <name>Skill Point List</name>
                        </target>
                        <target>
                        <category>skill</category>
                        <name>Total Skill
                        Points</name>
                        </target>
                        </targets>
                        </object>


                        Is repeated for every class for every level 1 to 20, with only the
                        level and the class name changing. Maybe it's not possible in your
                        schema to have a 'use this macro, but replace classname with Cleric,
                        and level with 3' type function. It would dramatically lower your
                        file-size, and may even speed up initialization/load time.

                        That's just a first impression. Nice job - obviously you've put a lot
                        of effort into this!

                        -Bryan
                        Benevolent Dictator of PCGen

                        --- In pcgen-xml@yahoogroups.com, "andargor" <andargor@y...> wrote:
                        > Hi all,
                        >
                        > I coded up a little demo to illustrate the advantages of using
                        > independent XML objects for character generators.
                        >
                        > It's a little too large to be put in the Files section (1.5MB), so
                        > it's on my site:
                        >
                        > http://www.andargor.com/files/panther-demo.zip
                        >
                        > - Unzip to any directory
                        > - Read the README for the explanation on the approach
                        > - Execute panther.exe for a sample character
                        >
                        > I'd love to hear your comments,
                        >
                        > Andargor
                      • andargor
                        ... Thanks for the comment Bryan. Yes, that was the plan, to use object templates , but I didn t have the time to implement them :) Actually, the classes file
                        Message 11 of 15 , May 26, 2004
                        • 0 Attachment
                          --- In pcgen-xml@yahoogroups.com, "merton_monk" <merton_monk@y...> wrote:

                          > Is repeated for every class for every level 1 to 20, with only the
                          > level and the class name changing. Maybe it's not possible in your
                          > schema to have a 'use this macro, but replace classname with Cleric,
                          > and level with 3' type function. It would dramatically lower your
                          > file-size, and may even speed up initialization/load time.
                          >
                          > That's just a first impression. Nice job - obviously you've put a lot
                          > of effort into this!
                          >
                          > -Bryan
                          > Benevolent Dictator of PCGen

                          Thanks for the comment Bryan. Yes, that was the plan, to use "object
                          templates", but I didn't have the time to implement them :)

                          Actually, the classes file is generated by a perl script for now :D

                          There are a lot of other optimizations that are needed, particularly
                          memory usage, speeding up XPath lookups with indices, etc. All in good
                          time...

                          Andargor
                        • merton_monk
                          ... the ... your ... Cleric, ... your ... lot ... I assumed you had used a script of some kind - typing all of that in would have left you with major carpal
                          Message 12 of 15 , May 28, 2004
                          • 0 Attachment
                            --- In pcgen-xml@yahoogroups.com, "andargor" <andargor@y...> wrote:
                            > --- In pcgen-xml@yahoogroups.com, "merton_monk" <merton_monk@y...>
                            wrote:
                            >
                            > > Is repeated for every class for every level 1 to 20, with only
                            the
                            > > level and the class name changing. Maybe it's not possible in
                            your
                            > > schema to have a 'use this macro, but replace classname with
                            Cleric,
                            > > and level with 3' type function. It would dramatically lower
                            your
                            > > file-size, and may even speed up initialization/load time.
                            > >
                            > > That's just a first impression. Nice job - obviously you've put a
                            lot
                            > > of effort into this!
                            > >
                            > > -Bryan
                            > > Benevolent Dictator of PCGen
                            >
                            > Thanks for the comment Bryan. Yes, that was the plan, to use "object
                            > templates", but I didn't have the time to implement them :)
                            >
                            > Actually, the classes file is generated by a perl script for now :D

                            I assumed you had used a script of some kind - typing all of that in
                            would have left you with major carpal tunnel! I know my hands were
                            sore for a few days when I first typed in the Spells from the PHB
                            when 3e first came out.... ;)

                            -Bryan

                            >
                            > There are a lot of other optimizations that are needed, particularly
                            > memory usage, speeding up XPath lookups with indices, etc. All in
                            good
                            > time...
                            >
                            > Andargor
                          Your message has been successfully submitted and would be delivered to recipients shortly.