Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

Inclusions process for XML files #64

Open
canercandan opened this issue Dec 12, 2014 · 3 comments
Open

Inclusions process for XML files #64

canercandan opened this issue Dec 12, 2014 · 3 comments

Comments

@canercandan
Copy link

Something that I am using quite a lot with my models is the ability to include XML files into others. I was usually doing it in hand-writing every time a GSL script to include a specific file (similarly to the example provided by the GSL guide) but honestly that sucks ;-) and I guess it's not in the MOP spirit. That's why I created a recursive function that includes every single node named include with an attribute file.

Here's an example of model in XML including other XML files:

script.gsl:

.template 0
process_inclusion()
.endtemplate

project.xml:

<project script="script.gsl">
  <include file="file1"/>
  <include file="file2"/>
</project>

file1.xml:

<file1_markup/>

file2.xml:

<file2_markup/>
<file2_markup/>
<file2_markup/>
<include file="file3/file3"/>

file3/file3.xml:

<file3_markup/>
<file3_markup/>

Here is the actual source code of the function:

.template 0

function global.process_inclusion(context)
  my.context ?= project

  my.found = 1
  while my.found
    my.found = 0
    for my.context.include as i
      # include file [i.file].xml
      xml to my.context from "$(i.file:).xml"
      delete i
      my.found = 1
    endfor
  endwhile

  for my.context. as ii where ii.name()?"include" <> "include"
    process_inclusion(ii)
  endfor
endfunction

.endtemplate

Another solution could be to use the XInclude XML inclusion mechanism, here is the w3c rfc: http://www.w3.org/TR/xinclude/

@hintjens
Copy link
Member

This is really neat, your other pieces of code too.

Why not add these to the GSL repository, perhaps in a new directory?

On Fri, Dec 12, 2014 at 2:46 PM, Caner Candan [email protected]
wrote:

Something that I am using quite a lot with my models is the ability to
include XML files into others. I was usually doing it in hand-writing every
time a GSL script to include a specific file (similarly to the example
provided by the GSL guide) but honestly that sucks ;-) and I guess it's not
in the MOP spirit. That's why I created a recursive function that includes
every single node named include with an attribute file.

Here's a example of model in XML including other XML files:

script.gsl:

.template 0
process_inclusion()
.endtemplate

project.xml:

file1.xml:

<file1_markup/>

file2.xml:

<file2_markup/>
<file2_markup/>
<file2_markup/>

file3/file3.xml:

<file3_markup/>
<file3_markup/>

Here is the actual source code of the function:

.template 0

function global.process_inclusion(context)
my.context ?= project

my.found = 1
while my.found
my.found = 0
for my.context.include as i
# include file [i.file].xml
xml to my.context from "$(i.file:).xml"
delete i
my.found = 1
endfor
endwhile

for my.context. as ii where ii.name()?"include" <> "include"
process_inclusion(ii)
endfor
endfunction

.endtemplate


Reply to this email directly or view it on GitHub
#64.

@canercandan
Copy link
Author

Hi @hintjens,

Thanks I appreciate, regarding your suggestion, I have no idea about the best place in the GSL repository to host them.

BTW, is there an easy way to add this new function as a builtin GSL function ? Maybe it could even be better to reimplement it in C code. What do you think ?

@hintjens
Copy link
Member

GSL uses .gxl files to build new classes in C, generating the hooks to plug
that into the GSL main. It's not trivial though.

On Sat, Dec 13, 2014 at 10:13 AM, Caner Candan [email protected]
wrote:

Hi @hintjens https://github.com/hintjens,

Thanks I appreciate, regarding your suggestion, I have no idea about the
best place in the GSL repository to host them.

BTW, is there an easy way to add this new function as a builtin GSL
function ? Maybe it could even be better to reimplement it in C code. What
do you think ?


Reply to this email directly or view it on GitHub
#64 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants