How to have a varible out of the Document.

1 view
Skip to first unread message

sweta

unread,
Feb 10, 2010, 9:02:54 AM2/10/10
to Open Mashup Alliance Interest Group
Hi,

I have a script that inovokes a web service on my machine, it is as
follows,

<mashup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openemml.org/2009-04-15/
EMMLSchema ../schemas/EMMLSpec.xsd"
xmlns="http://www.openemml.org/2009-04-15/EMMLSchema"
name="checkAvailability">
<input name="userName" type="string" default="sweta" />
<input name="password" type="string" default="livelife" />
<input name="location" type="string" default="Jaipur"/>
<input name="roomType" type="string" default="OID:15"/>

<input name="startDate" type="string" default="Jan 1, 2010"/>
<input name="endDate" type="string" default="Jan 12, 2010"/>
<output name="result" type="document"/>
<variable name="formInvocation" type="document"/>
<variable name="temp" type="document"/>
<variable name="final" type="string"/>
<variable name="final1" type="document"/>
<variable name="auth" type="string"/>
<variable name="ar" type="string"/>

<variables>

<variable name="responseCode" type="string" />

</variables>
<!--<directinvoke endpoint="http://localhost:8080/object/OID:27"
outputvariable="$temp"/>
<assign fromexpr="$temp//div[@class='nof-actions']//tr/td[9]//form"
outputvariable="$result"/>-->


<directinvoke endpoint="http://localhost:8080/object/OID:27/action/
checkAvailability(java.lang.String,org.hotel_booking.roomtype.RoomType,org.nakedobjects.applib.value.Date,org.nakedobjects.applib.value.Date)"
method="POST"
arg0="$location"
arg1="$roomType"
arg2="$startDate"
arg3="$endDate"
username="$userName"
password="$password"
outputvariable="$temp"/>
<assign fromexpr="$temp//div[@class='nof-action-result']//ul//li/a"
tovariable="$result"/>

The output comes to be..

<?xml version="1.0" encoding="UTF-8"?>
<a class="nof-action-result" href="/object/OID:2B" rel="object"
rev="results">XYZ VO409 Classic</a>
<?xml version="1.0" encoding="UTF-8"?>
<a class="nof-action-result" href="/object/OID:19" rel="object"
rev="results">XYZ AL401 Classic</a>


Instead of just two <a> tag lines

Why is so?

and if i want to get Just OID:19 and OID:2B as string variables how
should i do it.. i am aware it will be with the javascript, but then
in that case how should i cope up with two lines of output being in
document variable to be in string variable?

Sara Mitchell

unread,
Feb 12, 2010, 2:40:04 PM2/12/10
to open-mashu...@googlegroups.com
Your output variable is type "document" meaning that the result must be a well formed document, starting with the <?xml ?> declaration and being completely wrapped in a root node.

The XPath expression in <assign> ends up selecting 2 <a> elements which is a node set (2 nodes, not wrapped in a root node), so the EMML Engine is correctly sending each of those nodes out as a document. And that is why you have 2 <?xml?> declarations -- one for each document.

You can avoid this by adding a root node around the result of your <assign> statement with something like this:

<!-- this implicitly creates a document type variable named temp2, but you can declare this also -->
<assign fromexpr="$temp//div[@class='nof-action-result']//ul//li/a" tovariable="$temp2"/>

<!-- wrap <root> around node set in temp2 -->
<constructor outputvariable="$result">
<root> {$temp2}</root>
</constructor>

The <constructor> statement is both constructing a document and assigning it to the result output variable. It uses dynamic mashup expressions to pull in the nodes from temp2.

Sara
--- On Wed, 2/10/10, sweta <desai...@gmail.com> wrote:

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

sweta

unread,
Feb 15, 2010, 12:51:44 AM2/15/10
to Open Mashup Alliance Interest Group
Hi Sara,

Thanks for a great help. Its giving me the required output now..

Thanks again,
Sweta.. :-)

On Feb 13, 12:40 am, Sara Mitchell <samitche...@yahoo.com> wrote:
> Your output variable is type "document" meaning that the result must be a well formed document, starting with the <?xml ?> declaration and being completely wrapped in a root node.
>
> The XPath expression in <assign> ends up selecting 2 <a> elements which is a node set (2 nodes, not wrapped in a root node), so the EMML Engine is correctly sending each of those nodes out as a document. And that is why you have 2  <?xml?> declarations -- one for each document.
>
> You can avoid this by adding a root node around the result of your <assign> statement with something like this:
>
> <!-- this implicitly creates a document type variable named temp2, but you can declare this also -->
> <assign fromexpr="$temp//div[@class='nof-action-result']//ul//li/a" tovariable="$temp2"/>
>
> <!-- wrap <root> around node set in temp2 -->
> <constructor outputvariable="$result">
> <root> {$temp2}</root>
> </constructor>
>
> The <constructor> statement is both constructing a document and assigning it to the result output variable. It uses dynamic mashup expressions to pull in the nodes from temp2.
>
> Sara

> --- On Wed, 2/10/10, sweta <desai3sw...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages