Inserting an XML fragment into a variable

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Hi mashers,

Well I guess it's the folks at Jackbe :) ...

Simple question I hope. How do you insert an XML fragment within another document/variable?

I've a list of nodes which I want to insert into a variable at a certain point within the structure of another variable. I've produce a list of RSS items from a foreach loop which I now want to insert into my output variable as child nodes of channel. I started by using the constructor to build my RSS output variable like this:

<rss>

<channel>

<title>blah blah</title>

<link>http://.... etc</link>

<description>etc etc</description>

</channel>

</rss>

Now I want to insert a list of <item></item> elements from another variable into my output variable between the <channel></channel>, but do you think I can get it right. I've tried appendresult, annotate and even assign, but it just doesn't come out in the format I wanted.

Suggestions on the best approach.

Many thanks, Innes (NZ)

 

0
Your rating: None
aishmishra
aishmishra's picture
User offline. Last seen 10 weeks 6 days ago. Offline
Joined: 09/24/2008
Points: 3

 Hi,

Your query pertains to a programming approach and may be achieved in more than one ways.

What came to my mind was to just add the variable containing the item elements when you are using constructor to create the rss output variable. Something like this

<constructor outputvariable="constructor_var">

<rss>

<channel>

{$item_variable}

<title>blah blah</title>

<link>http://.... etc</link>

<description>etc etc</description>

</channel>

</rss>

</constructor>

 

Here is an example that I tried out

<mashup>

<output name="constructor_master" type="document"/>

<constructor outputvariable="constructor_slave">

<item>

<items>presto1</items>

<items>presto2</items>

</item>

</constructor>

<constructor outputvariable="constructor_master">

<rss>

<channel>

{$constructor_slave//items}

<title>blah blah</title>

<link>http://.... etc</link>

<description>etc etc</description>

</channel>

</rss>

</constructor>

</mashup>

Do let us know if it helps

smitchell
smitchell's picture
User offline. Last seen 16 hours 44 min ago. Offline
Joined: 08/29/2008
Points: 34

Just for clarity, this technique uses a dynamic mashup expression for an entire variable and <constructor> to wrap the structured  content in the variable with a root node and other ancestors.

Most of the examples in documentation for dynamic mashup expressions point to just simple data or a single node -- but they are not restricted to this.

Sara, technical writer/jackbe

 

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Hi guys,

thanks for your input. I really appreciate that you take the time with us beginners.

Your suggestion worked perfectly. I've now finished and published my first hand-coded mashup using Studio and EMML. I'm quite proud of the achievement  and am looking forward to doing more. If it's worthwhile I can post the finished emml file for others to see. It uses a Dapper feed to build an RSS mashup. It's pretty basic, and it may not be the most elegant or efficient, but it worked.

Cheers, Innes

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

See my other post related to another problem in developing my mashup, for the solution. Cheers, Innes (NZ)

http://www.jackbe.com/enterprise-mashup/forum/foreach-loop-produces-no-r...