Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
DavidETL
Contributor III
Contributor III

XML API to CSV - Content is not allowed in prolog.

Hello

 

I need some community support with using the tRest---->xmlfield---->FileoutDelimited.

 

  1.  I am trying to extract information from https://tatts.com/pagedata/racing/2017/7/7/RaceDay.xml   (this is a free public API)
  2. I have configured the flow as best i believe accurate based on the research on these forums.
  3. When i first select the URL in the tRest it only ever shows me Body or ERROR_CODE. I suspect this was normal so i then used tExtractXMLField to extract the data from the body
  4. In the tExtractXML field if i click sync Columns it only syncs the two BODY and ERROR_CODE. So instead of this i clicked on "EDIT SCHEMA" and created the columns i wanted so it would appear in the Mapping
  5. I then set the loop Xpath query to "/RaceDay/RaceDay" as i only wanted to test if i could get the very first level.
  6. I then mapped each column to the exact path.
  7. When i run the job it i get the error "Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog." in the CSV file it creates the heading for each column but no data.

Any help on this would be much appreciated. Screens are below. 

0683p000009LvOy.jpg0683p000009LvP8.jpg0683p000009Lv5U.jpg

0683p000009LvPD.jpg

 

 

Labels (5)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hello
I got the same error with tExtractXMLFields, however, it works if I write the response to a file with tHttpRequest and then use a tFileInputXML to read the file. see

0683p000009LvP9.png0683p000009Luln.png

 

Regards

Shong

View solution in original post

4 Replies
Anonymous
Not applicable

Hello
I got the same error with tExtractXMLFields, however, it works if I write the response to a file with tHttpRequest and then use a tFileInputXML to read the file. see

0683p000009LvP9.png0683p000009Luln.png

 

Regards

Shong

DavidETL
Contributor III
Contributor III
Author

Hi Shong,

 

that worked well thank you very much. Im not explorer how to create a variable and rotate through the date in the URL. For example if i set the job to run through every date from today + 3 days from now. do you have any advice on where to start with this?

 

kind regards

 

David

Anonymous
Not applicable

Hello
If i understand your request well, you want to loop a date range and call the API for each date. To achieve it, you need to use a tLoop to do a loop for the API calling, eg:
tLoop--iterate--tJava--oncomponentok--tHttpRequest--oncomponentok--other components.
on tLoop, check 'For' loop type, set From as 0, To as 3, and Step as 1.
on tJava, build a dynamic URL for used on tHttpRequest:

int i=((Integer)globalMap.get("tLoop_1_CURRENT_VALUE"));
java.util.Date currentDate=TalendDate.getCurrentDate();
String stringDate=(TalendDate.formatDate("yyyy/MM/dd",TalendDate.addDate(currentDate, i, "dd"))).replaceAll("/0","/");

//System.out.println(stringDate);
context.URL="https://tatts.com/pagedata/racing/"+stringDate+"/RaceDay.xml";

on tHttpRequest, set the URL with context variable context.URL

Regards
Shong

DavidETL
Contributor III
Contributor III
Author

Thanks again Shong. Proposed solution worked. Originaly i got working with just placing 

"https://tatts.com/pagedata/racing/"+TalendDate.getDate("yyyy/M/d")+"/NRFields.xml"

in the URL but it would only get one date.

 

i will start another post with a different heading as i am now trying to get the URL to change based of a dynamic list which comes from another HTTP XML request.

 

thanks again, much appreciated.

 

kind regards


David