f



Help with passing xml tags within an xml file

Let's say I have the following tags in an xml:


<World>
    <Country>Canada</Country>
    <Hemisphere>North</Hemisphere>
    <Weather climate="cold" forecast="snow">
        <CommandAction>$(HOME)\calculate.py Canada North
snow</CommandAction>
    </Weather>
</World>

The CommandAction tag will invoke some python script which takes
Country Hemisphere and forecast as parameters.  Is there a way to
generalize the CommandAction tag so that it can look something like the
following:

<CommandAction>$(HOME)\calculate.py <Country> <Hemisphere>
<forecast></CommandAction>

I'm not very experienced with xml and I would like to know if the above
is a proper way of doing what I want. Any help please?

Thanks
Thierry

0
lamthierry (65)
2/14/2006 3:46:01 PM
comp.text.xml 8781 articles. 0 followers. Post Follow

5 Replies
810 Views

Similar Articles

[PageSpeed] 10

Thierry wrote:
> Let's say I have the following tags in an xml:
> 
> 
> <World>
>     <Country>Canada</Country>
>     <Hemisphere>North</Hemisphere>
>     <Weather climate="cold" forecast="snow">
>         <CommandAction>$(HOME)\calculate.py Canada North
> snow</CommandAction>
>     </Weather>
> </World>
> 
> The CommandAction tag will invoke some python script which takes
> Country Hemisphere and forecast as parameters.  Is there a way to
> generalize the CommandAction tag so that it can look something like the
> following:
> 
> <CommandAction>$(HOME)\calculate.py <Country> <Hemisphere>
> <forecast></CommandAction>
> 
> I'm not very experienced with xml and I would like to know if the above
> is a proper way of doing what I want. Any help please?

A more manipulable construction might look something like:

<World>
     <Country>Canada</Country>
     <Hemisphere>North</Hemisphere>
     <Weather climate="cold" forecast="snow">
         <CommandAction location="home">
             <script>calculate.py</script>
             <param value="Country"/>
             <param value="Hemisphere"/>
             <param value="Weather/@forecast"/>
         </CommandAction>
     </Weather>
</World>

Then you can write some XSLT to create output which some processor 
(Python) can execute. XML itself can't run programs, because it is
not itself a programming language.

(In fact, you'd need to write XSLT to write XSLT. The double
indirection is needed because XSLT is not dynamic and cannot re-rig
itself internally during execution to reflect a value it has only
just come across (like the XPath syntax implied in my <param>
elements.)

///Peter
-- 
XML FAQ: http://xml.silmaril.ie/
0
Peter
2/15/2006 12:16:14 AM
Peter Flynn wrote:
> Thierry wrote:
> 
>> Let's say I have the following tags in an xml:
>>
>>
>> <World>
>>     <Country>Canada</Country>
>>     <Hemisphere>North</Hemisphere>
>>     <Weather climate="cold" forecast="snow">
>>         <CommandAction>$(HOME)\calculate.py Canada North
>> snow</CommandAction>
>>     </Weather>
>> </World>
>>
>> The CommandAction tag will invoke some python script which takes
>> Country Hemisphere and forecast as parameters.  Is there a way to
>> generalize the CommandAction tag so that it can look something like the
>> following:
>>
>> <CommandAction>$(HOME)\calculate.py <Country> <Hemisphere>
>> <forecast></CommandAction>
>>
>> I'm not very experienced with xml and I would like to know if the above
>> is a proper way of doing what I want. Any help please?
> 
> 
> A more manipulable construction might look something like:
> 
> <World>
>     <Country>Canada</Country>
>     <Hemisphere>North</Hemisphere>
>     <Weather climate="cold" forecast="snow">
>         <CommandAction location="home">
>             <script>calculate.py</script>
>             <param value="Country"/>
>             <param value="Hemisphere"/>
>             <param value="Weather/@forecast"/>
>         </CommandAction>
>     </Weather>
> </World>
> 
> Then you can write some XSLT to create output which some processor 
> (Python) can execute. XML itself can't run programs, because it is
> not itself a programming language.

XML is used for anything, it can be used like a programming language as well

-don't you think that XSLT is itself a kind of programming language ? 
(it reads an input, processes it, and produces an output, even if the 
input must be XML)

-I designed myself a general purpose language :)
have a look here :
http://disc.inria.fr/perso/philippe.poulard/xml/active-tags/
and here :
http://reflex.gforge.inria.fr/
(this is the engine that implement all that stuff)

a nice toy ;)

> 
> (In fact, you'd need to write XSLT to write XSLT. The double
> indirection is needed because XSLT is not dynamic and cannot re-rig
> itself internally during execution to reflect a value it has only
> just come across (like the XPath syntax implied in my <param>
> elements.)
> 
> ///Peter


-- 
Cordialement,

               ///
              (. .)
  --------ooO--(_)--Ooo--------
|      Philippe Poulard       |
  -----------------------------
  http://reflex.gforge.inria.fr/
        Have the RefleX !
0
2/15/2006 2:19:52 PM
Philippe Poulard wrote:
> XML is used for anything, it can be used like a programming language as 
> well

Not exactly. XML itself is pure syntax. You can use that syntax to 
express any kind of data, including program stucture. Think of XML as a 
toolkit for writing languages.

> -don't you think that XSLT is itself a kind of programming language ? 

XSLT is very explicitly a nonprocedural rule-based programming language.

-- 
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
0
2/15/2006 3:40:04 PM
Joseph Kesselman wrote:
> Philippe Poulard wrote:
> 
>> XML is used for anything, it can be used like a programming language 
>> as well
> 
> 
> Not exactly. XML itself is pure syntax. You can use that syntax to 
> express any kind of data, including program stucture. Think of XML as a 
> toolkit for writing languages.

This is exactly what I meant

> 
>> -don't you think that XSLT is itself a kind of programming language ? 
> 
> 
> XSLT is very explicitly a nonprocedural rule-based programming language.
> 

You said it ;)

No comment about Active Tags ?

-- 
Cordialement,

               ///
              (. .)
  --------ooO--(_)--Ooo--------
|      Philippe Poulard       |
  -----------------------------
  http://reflex.gforge.inria.fr/
        Have the RefleX !
0
2/15/2006 3:46:21 PM
Philippe Poulard wrote:
> Peter Flynn wrote:
[...]
 >> XML itself can't run programs, because it is
>> not itself a programming language.
> 
> XML is used for anything, it can be used like a programming language as 
> well

Read what I wrote. Yes of course XML syntax can be used to represent
programming language constructs -- as you say, XSLT is a programming
language -- but XML *itself* is not a programming language: it's just
a specification for a markup syntax that can be used to identify lots
of different things.

///Peter
-- 
XML FAQ: http://xml.silmaril.ie/
0
Peter
2/15/2006 10:24:15 PM
Reply: