Skip to Content
avatar image
Former Member

How do you loop nested nodes from a web service call?

Hi Experts,

I'm stuck in trying to access data from a web service call made with an Adaptive Web Service model.

Here is what the model context looks like, I'll put the cardinality next to each one.


Root
   Request_SearchQuery (0..n)
      Response (0..1)
         SearchQueryReturn (0..1)
            Record (0..n)
               Record1 (1..1)
                  Field (0..n)
                     Field1 (0..1)
                        stringValue (valuedata; contains data pertaining to field name)
                  stringName (metadata; contains field name)
      SearchQuery (0..1)

SearchQuery (0..1) takes the initial values to execute the query.

Record (0..n) contains how many rows in the table

Field (0..n) contains how many fields in a row

stringName is the name of the field (ie table column name)

stringValue is the data value for the particular field.

I am having severe trouble looping the fields and records as I do not know what methods to use out of the web dynpro API.

I need to loop through all fields in one record (table row) and then move to the next record and loop all the fields etc. The weird thing is the webservice returns the field name under node Field, and the field value under node Field1.

Please help.

M

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Jul 02, 2009 at 05:31 AM

    Hi Marshall Mathers,

    Please find the below code. It will give you some idea.

    I couldn't paste the exact code (syntax) since I don't know the singleton property of each node. If you want me to give the exact code please paste your singleton property value of each node.

    int noOfRows = wdContext.nodeRecord().size();
    for(int row=0;row<noOfRows;row++)
    {
       wdContext.nodeRecord().getRecordElementAt(row).	
       get element of Record1 element.
        get Field node from Record 1 Node
         int fieldsSize = wdContext.nodeField().size();
           for(int fields =0; fields<fieldsSize; fields++)
           {
              String fieldName = wdContext.nodeField().getElementAtXXXXX(fields).getStringName();
    String fieldValue = "";
    if(size of node field1 > 0)
    {
    // According to the cardinality, Field1 node will contain either one element or Zero. So no need of any for loop here.
     fieldValue = get String value from field1;  
    }
           }
    
    }
    

    Regards,

    Jaya.

    Edited by: VJR on Jul 2, 2009 11:02 AM

    Edited by: VJR on Jul 2, 2009 11:03 AM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Jaya,

      I know your code makes logical sense but there are no such methods in the API as:

      
      get element of Record1 element.
      
      get Field node from Record 1 Node
      
      

      if you think there is, please use actual code to show me and not pseudocode.

      Kind regards,

      Marshall.

  • avatar image
    Former Member
    Jul 02, 2009 at 02:22 PM

    To answer your question, I need to know the value of the "singleton"-property for all context nodes.

    Armin

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Try

      for (int i = 0; i < wdContext.nodeRecord().size(); ++i)
      {
        IRecordElement r = wdContext.nodeRecord().getRecordElementAt(i);
        wdContext.nodeRecord().moveTo(i);
        for (int j = 0; i < wdContext.nodeField().size(); ++j)
        {
          IFieldElement field = wdContext.nodeField().getFieldElementAt(j);
        }
      

      Armin