Mashup Code Sample - WebClipping Mashup example with EMML and JavaScript

In this mashup you can see how to do a simple webclipping from the Office Max online store using the directInvoke function in emml

<variable name="endpointURLPrefix" type="string" default="http://www.officemax.com.mx/store/detail.aspx?ID="   />
<!-- Building the endpoint with the parameter -->
          <assign outputvariable="endpointURL" fromexpr="concat($endpointURLPrefix,$productId)"    />
<!-- Calling the endpoint webpage -->
          <directinvoke endpoint="$endpointURL" method="GET" outputvariable="htmlResult"   />

and get´s the price of a specific product parsing the output with JavaScript.

<!-- Parsing the output with javascript -->
        <script type="text/javascript">
            <![CDATA[           
            var r = new String(htmlResult);
            var text="</span>$";
            var index = r.indexOf(text);           
            var resultTmp = r.substring(index);
            index=resultTmp.indexOf(".");
            productPrice= resultTmp.substring((text.length),index+3);
            ]]>
        </script>   

This approach is only good only when the output is not a well formed XML. Other wise I recomend to use XPath to parse the output as in WebClipping Mashup example with EMML and XPath.

 

5
Your rating: None Average: 5 (1 vote)