How to deal with this XMLport error?

Aravindh_NavisionAravindh_Navision Member Posts: 258
Hi Friends,

I have an xml file as shown below.
- <RESPONSE>
     <EXPR>USD</EXPR> 
     <EXCH>ARS</EXCH> 
     <AMOUNT>1</AMOUNT> 
     <NPRICES>1</NPRICES> 
    - <CONVERSION>
        <DATE>Mon, 27 May 2013 19:00:00 GMT</DATE> 
        <ASK>0.1908</ASK> 
        <BID>0.1889</BID> 
     </CONVERSION>
</RESPONSE>

How can I import this into the newly created table with the fields above in xml file using XMLport?

I have made one design using XML port as below.
Node Name - Node Type - Source Type - Data Source

(Indentation 0)ExchangeRate - Element - Table - <Currency Conversion - Table>(Currency Conversion - Table)
(Indentation 1)  RESPONSE - Element - Text - <RESPONSE>
(Indentation 1)  EXPR - Element - Field - Currency Conversion - Table::EXPR
(Indentation 1)  EXCH - Element - Field - Currency Conversion - Table::EXCH
(Indentation 1)  AMOUNT - Element - Field	- Currency Conversion - Table::AMOUNT
(Indentation 1)  NPRICES - Element - Field - Currency Conversion - Table::NPRICES
(Indentation 1) CONVERSION - Element - Text - CONVERSION
(Indentation 1)  DATE - Element - Field - Currency Conversion - Table::DATE1
(Indentation 1) ASK - Element - Field - Currency Conversion - Table::ASK
(Indentation 1)  BID - Element - Field - Currency Conversion - Table::BID

Variables:
Name	        DataType	Subtype	Length

TestFile	        File		
InStreamObj	InStream		
OutStramObj	OutStream

From On Push trigger of button in form, I wrote the below code.
TestFile.OPEN('D:\MyFile.xml');
TestFile.CREATEINSTREAM(InStreamObj);
XMLPORT.IMPORT(50000,InStreamObj);
TestFile.CLOSE;

While clicking the button, I am getting the following error?

"The Element <RESPONSE> can not be found from object description."

Can anyone tell me why this error is popping up and how to deal with it?

Thanks,
Aravindh.

Comments

  • ara3nara3n Member Posts: 9,256
    Remove (Delete) ExchangeRate line and make RESPONSE of source type table with Currency Conversion - Table
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Thanks ara3n.

    After doing that, I'm getting error - "The element <CONVERSION> is unexpected."

    What to do to overcome this error?
  • ara3nara3n Member Posts: 9,256
    Can you paste your xml file in here?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Please find the XML file attached in JPEG format.

    Thanks,
    Aravindh.
  • ara3nara3n Member Posts: 9,256
    In your xmlport Date, ASK and BID need to be intented to 2 instead of 1. But conversion is correct.
    I'll try and see if I can replicate it.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    I just tried it with a text element and it works fine.
    OBJECT XMLport 50010 Test xmlport
    {
      OBJECT-PROPERTIES
      {
        Date=05/29/13;
        Time=10:08:55 AM;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
      }
      ELEMENTS
      {
        { [{8F14EBF6-D637-4128-957D-35DA9BD18FDE}];  ;RESPONSE            ;Element ;Text     }
    
        { [{A4F4D5BD-FEF4-41FF-B2BD-1E9EBC8F2B3F}];1 ;EXPR                ;Element ;Text     }
    
        { [{43EB9D27-0F55-40D2-900E-C0F390DA303E}];1 ;EXCH                ;Element ;Text     }
    
        { [{16662730-437F-4D42-8BF0-9EDDF06B1E3F}];1 ;AMOUNT              ;Element ;Text     }
    
        { [{C32D0F23-4572-485C-A0D8-1392A78C588C}];1 ;NPRICES             ;Element ;Text     }
    
        { [{00045B6C-F0E0-452F-885A-065EDB2023FE}];1 ;CONVERSION          ;Element ;Text     }
    
        { [{F087C801-C5B0-49F4-A754-2063F47105FA}];2 ;DATE                ;Element ;Text     }
    
        { [{C9E61516-37D5-4424-85BA-A55F6F8DE70C}];2 ;ASK                 ;Element ;Text     }
    
        { [{4FFBEF5C-B7A4-43EC-A59E-1885A1A8D636}];2 ;BID                 ;Element ;Text     }
    
      }
      EVENTS
      {
      }
      REQUESTPAGE
      {
        PROPERTIES
        {
        }
        CONTROLS
        {
        }
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    
    

    Does your xml file by any chance have multiple conversion elements?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    My hearty thanks to you ara3n. It is working now..!!

    I have one more doubt. If you see the <DATE> node...
    <DATE>[b]Tue, 28 May 2013 19:00:00 GMT[/b]</DATE>
    

    I need to convert this value to normal date format (05/28/2013) and send to the table. What to do for achieving this?

    Variables:

    strDay - strMonth - strYear are text variables.
    strDay := COPYSTR(DATE,6,2);
    strMonth := COPYSTR(DATE,9,3);
    strYear := COPYSTR(DATE,13,4);
    fnDate();
    strStartingDate := strMonth + '/' + strDay + '/' + strYear;
    

    I have done the above code. But I don't know how to proceed next?

    Thanks,
    Aravindh
  • jversusjjversusj Member Posts: 489
    search for the function DMY2DATE. Convert your string parsed values to integers and build the date you need.
    kind of fell into this...
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Thanks jversusj.

    Actually I need to send Tue, 28 May 2013 19:00:00 GMT as 05/28/2013 by converting it in XMLport itself and send to the table.

    I don't find problem in converting, I got strucked on how to send from XML port in desired format to the table.

    How to do this?
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Hi Guys,

    I solved this issue. You guys just have a look.
    strDay := COPYSTR(DATE,6,2);
    strMonth := COPYSTR(DATE,9,3);
    strYear := COPYSTR(DATE,13,4);
    fnDate();
    strStartingDate := strMonthNo + '/' + strDay + '/' + strYear;
    EVALUATE("<Currency Exchange Rate>"."Starting Date",strStartingDate);
    

    Actually I need to update in Currency Exchange Rate."Starting Date" field.

    Now I could able to insert it into the table field.
Sign In or Register to comment.