in reply to Re^10: aXML vs TT2
in thread aXML vs TT2

I think ikegami wants to ask you how you would write an aXML program that outputs another aXML program, or an aXML fragment. For example, how would the aXML program look that outputs the following string:

<db_select> <query> SELECT * FROM user ORDER BY id </query> <mask> <tr> <td><d>id</d></td> <td>[hlink action="user_profile" user_id="<d>id</d>"]<d>name</d> +[/hlink]</td> <td><d>email</d></td> </tr> </mask> </db_select>

If there is no way to prevent your language from seeing a character sequence as executable code, that is highly inconvenient.

Replies are listed 'Best First'.
Re^12: aXML vs TT2
by ikegami (Patriarch) on Oct 22, 2011 at 20:20 UTC

    I think ikegami wants to ask you how you would write an aXML program that outputs another aXML program

    That's one example, but I didn't have a specific example in mind.

    He's hardly going to be the only one who has elements named "inc", "query" or "d". I know of one that uses "query", and I know of a major bank that might use "d".

    That means I can't use aXML for 2 of the 4 XML formats I deal with.

      See my other reply.
        Nope, it doesn't acknowledge the problem.
Re^12: aXML vs TT2
by Logicus (Initiate) on Oct 22, 2011 at 23:33 UTC

    I noticed and solved this problem years ago. There are a bunch of ways it can be done. Your quite right that this is a special case and your quite right that it needs a special solution.

    Solution 1

    In aXML tags delimited by brackets of type ( ) (/) compute prior to their child tags unless their child tags are also of type ( ) (/)

    (ignore) <db_select> <query>.... ... ... </db_select> (/ignore)

    Where the ignore plugin takes all the data within it's scope, stores them in a memory location and inserts a special token which directs the parser to reinsert that data at that position immediately prior to exit after the processing of the rest of the document is complete.

    Solution 2

    Let's make the problem harder; we want to output a fragment of aXML which contains tags of type ( ) (/)

    For instance:

    (db_select) <query>... ... ... (/db_select)

    Clearly if we use the above method, the (db_select) (/db_select) tag will be computed prior to the (ignore) tag, in accordance with the rules of precedence for the tag types. In this case we need to seperate the data off into another file and insert the token which triggers the post processing inclusion routine mentioned above.

    We can do that by having a plugin called something like <post_inc> or <delay_include> or whatever, which takes a path to file which is to be included at the end without being processed. This tag loads the file, stores the data in memory and inserts the appropriate special token the same as above.

    Solution 3

    Let's say you don't want to use a separate file for some reason, perhaps you dislike having lots of small data files and you prefer a more monolithic approach. (*note1 see below)

    You can simply convert the brackets to the html standard for special chars :

    &lt;db_select&gt; &lt;query&gt; SELECT * FROM users &lt;/query&gt; ... ... &lt;/db_select&gt;

    The parser will then pass straight over it because it will not consider the string to contain any valid tags.

    Since you can also use tags of type ( ) (/) and [ ] [/] in aXML you have 4 extra specials in accordance with the same rules you have for html:

    [ ] [/] becomes &lsb; &rsb; &lsb;/&rsb; ( ) (/) becomes &lb; &rb; &lb;/&rb;

    I'm pretty sure this covers all the bases, and I haven't needed anything more esoteric than that yet in over 4 years of using aXML.




    *note1 ... eventually I'm planning to get round to writing an aXML aware editor that will make traversing structures composed of many small files quick and easy. I have mentioned how that will work elsewhere.
      Solution 3 would work, but it means "Rock & Roll" needs to be written as "Rock &amp;amp; Roll", and "$a <=> $b" needs to be written as "$a &amp;lt;=&amp;gt; $b". Is that really what you expect people to do?

        Not at all, "rock & roll" can be passed through as is without any side effects.