Re: SELECT=ALL Correlated Value in TXT (423 Views)
Reply
Frequent Advisor
chitoc
Posts: 31
Registered: ‎04-27-2012
Message 1 of 5 (431 Views)
Accepted Solution

SELECT=ALL Correlated Value in TXT

[ Edited ]

Hi

 

I have simple question with a twist

 

I wanted to save the correlated values in a text file.........but here is the TWIST

SAVE ALL CORREALTED VALUE for single parameter.....for example

 

this is web service call

 

web_service_call();

lr_xml_get_value("query","SelectAll=yes",LAST)

 

I wanted to save ALL the value of param1 in the txt log file.

 

Thanks

HP Expert
JerryYin
Posts: 95
Registered: ‎08-16-2011
Message 2 of 5 (423 Views)

Re: SELECT=ALL Correlated Value in TXT

Hi, 

 

Please check the example code below.

 

 

#include "as_web.h"

char * xml_input =
"<acme_org>"
" <accounts_dept>"
"<employee>"
" <name>John Smith</name>"
"<cubicle>227</cubicle>"
"<extension>2145</extension>"
"</employee>"
"</accounts_dept>"
"<engineering_dept>"
"<employee>"
"<name>Sue Jones</name>"
"<extension>2375</extension>"
"</employee>"
"</engineering_dept>"
"</acme_org>";

Action() {

int i, NumOfValues;
char buf[64];

lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter

NumOfValues= lr_xml_get_values("XML={XML_Input_Param}",
"ValueParam=OutputParam",
"Query=/acme_org/*/employee/extension",
"SelectAll=yes", LAST );

for ( i = 0; i < NumOfValues; i++) { /* Print multiple values of OutputParam */

sprintf (buf, "Retrieved value %d : {OutputParam_%d}", i+1, i+1);
lr_output_message(lr_eval_string(buf));
}

return 0;

Frequent Advisor
chitoc
Posts: 31
Registered: ‎04-27-2012
Message 3 of 5 (402 Views)

Re: SELECT=ALL Correlated Value in TXT

Thanks for the reply........but it is not working

 

Problem:

I need the output array SAVED in txt file. I have some input and its output wil be accounts which I need to save in the txt file.

 

here is what I did

 

    int status, i, NumOfValues;
    long pfile;
    char *filename = "D:\Logfile.txt";
    char BufAccountID[64];
    char *AccountID;

 

    NumOfValues = lr_xml_get_values("XML={response}",
                      "Query=//accountId",
                      "ValueParam=ValueAccountId",
                      "SelectAll=yes",
                      LAST);

    lr_message("count of account id %d", NumOfValues);

    pfile=fopen(filename,"w+");

    if(pfile==NULL)
    {
        printf("Error in open the file name - %s",filename);
        return -1;
    }

    else
    {
    

    for ( i = 0; i < NumOfValues; i++)
        { /* Print multiple values of ValueParam */

            sprintf (AccountID, "ValueAccountId_%d", i+1);
            lr_save_string(lr_eval_string("{AccountID}"),"BufaccountId");
            lr_message("the ID now %s",lr_eval_string("{BufaccountId}"));
            //fprintf(pfile,"AccountID = %s\n", lr_eval_string("{accountId}"));
            //fprintf(pfile,"BankID = %s\t AccountID = %s", lr_eval_string("{bankId}"),lr_eval_string("{accountId}"));
            //lr_output_message(lr_eval_string(BufAccountID[i]));
            fprintf(pfile,"AccountID = %s", lr_eval_string("{BufAccountID}"));
        }

    fclose(pfile);
    }

 

Thanks for the response

HP Expert
JerryYin
Posts: 95
Registered: ‎08-16-2011
Message 4 of 5 (390 Views)

Re: SELECT=ALL Correlated Value in TXT

[ Edited ]

Hi, 

 

There's some errors in your code. I fixed those error and pasted the sample code at the end. 

 

1, the AccountID should be a char array, so that you can print to that array. You must allocate some space for printing.

2, the lr_save_string and lr_eval_string is not used correctly in your code. Please try to read the help on those 2 apis.

 

 

Another suggestion is to open the extended log to see if the parameter substitutions are correct. Press F4 and select the log, check all in "Extended log"

 

 

Action()
{
    
    int status, i, NumOfValues;
    long pfile;
    char *filename = "C:\\Logfile.txt";
    char BufAccountID[64];
    char AccountID[128];
    char * xml_input = "XML="
		"<acme_org>"
		" <accounts_dept>"
		"<employee>"
		" <name>John Smith</name>"
		"<cubicle>227</cubicle>"
		"<extension>2145</extension>"
		"</employee>"
		"</accounts_dept>"
		"<engineering_dept>"
		"<employee>"
		"<name>Sue Jones</name>"
		"<extension>2375</extension>"
		"</employee>"
		"</engineering_dept>"
		"</acme_org>";
    NumOfValues = lr_xml_get_values(xml_input,
                      "Query=//name",
                      "ValueParam=ValueAccountId",
                      "SelectAll=yes",
                      LAST);
    

    lr_message("count of account id %d", NumOfValues);

    pfile=fopen(filename,"w+");

    if(pfile==NULL)
    {
        printf("Error in open the file name - %s",filename);
        return -1;
    }

    else
    {
    

        for ( i = 0; i < NumOfValues; i++)
        { /* Print multiple values of ValueParam */

            sprintf (AccountID, "{ValueAccountId_%d}", i+1);
            lr_message("the ID now %s",lr_eval_string(AccountID));
            fprintf(pfile,"AccountID = %s\n", lr_eval_string(AccountID));
        }

    fclose(pfile);
    }
 
    return 0;
}

 

 

Frequent Advisor
chitoc
Posts: 31
Registered: ‎04-27-2012
Message 5 of 5 (370 Views)

Re: SELECT=ALL Correlated Value in TXT

Thanks for the solution.......it is working as it supposed.......I am not good at string manipulation.....if you have some one liner please post....It will be great help to community

Thanks again
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.