<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Fetch data XML to JMP in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773588#M95488</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2024-07-17_21-28-12.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66251i33CBBBE1D0E801E1/image-size/large?v=v2&amp;amp;px=999" role="button" title="2024-07-17_21-28-12.png" alt="2024-07-17_21-28-12.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2024 13:32:30 GMT</pubDate>
    <dc:creator>lala</dc:creator>
    <dc:date>2024-07-17T13:32:30Z</dc:date>
    <item>
      <title>Fetch data XML to JMP</title>
      <link>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773540#M95479</link>
      <description>&lt;P&gt;Hi, I am trying to fetch weather data form XML (Finnish weather service - &lt;A href="https://en.ilmatieteenlaitos.fi/open-data-manual-fmi-wfs-services" target="_blank" rel="noopener"&gt;https://en.ilmatieteenlaitos.fi/open-data-manual-fmi-wfs-services&lt;/A&gt;) to JMP in a way that the user could define the time period. My code does not work, I always get the "Invalid HTTP request state" error message.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// User-defined start and end dates (modify as needed)
startDate = "2024-07-10";
endDate = "2024-07-24";

// Construct the URL with user-defined dates and parameters
url = "https://opendata.fmi.fi/wfs?service=WFS&amp;amp;version=2.0.0&amp;amp;request=getFeature&amp;amp;storedquery_id=fmi::observations::weather::timevaluepair&amp;amp;place=helsinki-vantaa_airport&amp;amp;timestep=1&amp;amp;starttime=" || startDate || "T00:00:00Z&amp;amp;endtime=" || endDate || "T23:59:59Z&amp;amp;parameters=temperature%2Chumidity%2Cpressure";

// Create HTTP request object
httpRequest = New HTTP Request();

// Send HTTP GET request
response = httpRequest &amp;lt;&amp;lt; Send("GET", url);

// Check if the request was successful
If(response &amp;lt;&amp;lt; Get Status Code == 200,

// Parse the XML response
    xmlResponse = response &amp;lt;&amp;lt; Get As XML,
    
// Extract data from XML response
    dataNodes = xmlResponse &amp;lt;&amp;lt; XPath("//wml2:MeasurementTVP"),
    
// Initialize lists to store data
    temperatureList = {},
    humidityList = {},
    pressureList = {},
    
// Loop through each data node and extract values
   ForEach(node in dataNodes,
        // Extract timestamp
        timestamp = node &amp;lt;&amp;lt; XPath("wml2:time"),
        
        // Extract temperature value
        temperature = node &amp;lt;&amp;lt; XPath("wml2:value[@parameter='temperature']"),
        temperatureValue = temperature &amp;lt;&amp;lt; NodeText,
        
        // Extract humidity value
        humidity = node &amp;lt;&amp;lt; XPath("wml2:value[@parameter='humidity']"),
        humidityValue = humidity &amp;lt;&amp;lt; NodeText,
        
        // Extract pressure value
        pressure = node &amp;lt;&amp;lt; XPath("wml2:value[@parameter='pressure']"),
        pressureValue = pressure &amp;lt;&amp;lt; NodeText,
        
        // Convert timestamp to JMP DateTime format
        timestampDT = Parse DateTime(timestamp, "YYYY-MM-DDThh:mm:ssZ"),
        
        // Append data to lists
        Append(temperatureList, {timestampDT, As Number(temperatureValue)}),
        Append(humidityList, {timestampDT, As Number(humidityValue)}),
        Append(pressureList, {timestampDT, As Number(pressureValue)})
    );
    
    // Create a new JMP data table and add columns
    dt = New Table("Helsinki-Vantaa Weather Data",
        Add Rows(Num Rows(temperatureList)),
        New Column("Timestamp", Numeric, "DateTime"),
        New Column("Temperature (°C)", Numeric, "Continuous", Format(3)),
        New Column("Relative Humidity (%)", Numeric, "Continuous", Format(3)),
        New Column("Pressure (hPa)", Numeric, "Continuous", Format(3))
    );
    
// Populate the data table with values
    dt:"Timestamp" &amp;lt;&amp;lt; Set Values(temperatureList);
    dt:"Temperature (°C)" &amp;lt;&amp;lt; Set Values(humidityList);
    dt:"Relative Humidity (%)" &amp;lt;&amp;lt; Set Values(pressureList);
    dt:"Pressure (hPa)" &amp;lt;&amp;lt; Set Values(pressureList);
    
// Show the data table
    dt &amp;lt;&amp;lt; Show;
,
// Display error if request failed
    Throw("Failed to fetch data. HTTP status code: " || Char(response &amp;lt;&amp;lt; Get Status Code))
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jul 2024 08:35:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773540#M95479</guid>
      <dc:creator>IloinenHamsteri</dc:creator>
      <dc:date>2024-07-17T08:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data XML to JMP</title>
      <link>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773550#M95480</link>
      <description>&lt;P&gt;The syntax for New HTTP Request is incorrect. Here is small example which should return some data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

startDate = "2024-07-10";
endDate = "2024-07-11";

// Construct the URL with user-defined dates and parameters
url = "https://opendata.fmi.fi/wfs?service=WFS&amp;amp;version=2.0.0&amp;amp;request=getFeature&amp;amp;storedquery_id=fmi::observations::weather::timevaluepair&amp;amp;place=helsinki-vantaa_airport&amp;amp;timestep=1&amp;amp;starttime=" || startDate || "T00:00:00Z&amp;amp;endtime=" || endDate || "T23:59:59Z&amp;amp;parameters=temperature%2Chumidity%2Cpressure";

// Create HTTP request object
request = New HTTP Request(
	Method("GET"),
	URL(url)
);

data = request &amp;lt;&amp;lt; send;

/*
Show(request &amp;lt;&amp;lt; Get MIME Type);
*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jul 2024 08:41:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773550#M95480</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-07-17T08:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data XML to JMP</title>
      <link>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773580#M95486</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;the HTTP request works now, but it seems that the rest of the script is faulty as well. This is the first time I am trying to get data from XML.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 12:55:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773580#M95486</guid>
      <dc:creator>IloinenHamsteri</dc:creator>
      <dc:date>2024-07-17T12:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data XML to JMP</title>
      <link>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773586#M95487</link>
      <description>&lt;P&gt;It seems like you are using LLM generated cod? If so, they are in my opinion horrible with JSL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest you save the resulting data as xml file and use JMP's preview to get the source script&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1721221516121.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66246i8E99554128EE6615/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1721221516121.png" alt="jthi_0-1721221516121.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This will require some playing around but it can be parsed with this (or could use &lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/character-functions-2.shtml?os=win&amp;amp;source=application#ww4554589" target="_blank" rel="noopener"&gt;XPath Query()&lt;/A&gt; or &lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/parse-xml.shtml" target="_blank" rel="noopener"&gt;Parse XML()&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1721221576933.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66247i623F3FB00826905A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1721221576933.png" alt="jthi_1-1721221576933.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You can then use the source script to automate your process further and you can end up with something like&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_3-1721222207103.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66249i6C84DC45C99BC53B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_3-1721222207103.png" alt="jthi_3-1721222207103.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_4-1721222233652.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66250iB6E928AA458F9564/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_4-1721222233652.png" alt="jthi_4-1721222233652.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 13:17:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773586#M95487</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-07-17T13:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data XML to JMP</title>
      <link>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773588#M95488</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2024-07-17_21-28-12.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66251i33CBBBE1D0E801E1/image-size/large?v=v2&amp;amp;px=999" role="button" title="2024-07-17_21-28-12.png" alt="2024-07-17_21-28-12.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 13:32:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773588#M95488</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2024-07-17T13:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data XML to JMP</title>
      <link>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773593#M95490</link>
      <description>&lt;P&gt;Below is the script I used (I have used Ilmatieteenlaitos open data in JMP earlier but I think I either used different data or parsed it in a bit different way). It does use some more advanced techniques such as open(char to blob(), "text"), but that can be avoided by just saving the file first as text file. It also has data cleanup and graph creation (verify that the data it creates is correct, I didn't do any checks for that).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
/*
https://en.ilmatieteenlaitos.fi/open-data
	https://en.ilmatieteenlaitos.fi/open-data-manual-accessing-data
*/

location = "helsinki-vantaa_airport";
start_date = "2024-07-10";
end_date = "2024-07-11";

fmi_url = "https://opendata.fmi.fi/wfs?service=WFS&amp;amp;version=2.0.0&amp;amp;request=getFeature&amp;amp;storedquery_id=fmi::observations::weather::timevaluepair&amp;amp;place=^location^&amp;amp;timestep=1&amp;amp;starttime=^start_date^T00:00:00Z&amp;amp;endtime=^end_date^T23:59:59Z&amp;amp;parameters=temperature%2Chumidity%2Cpressure";


// Create HTTP request object
request = New HTTP Request(
	Method("GET"),
	URL(Eval Insert(fmi_url))
);

data = request &amp;lt;&amp;lt; send;

dt = Open(
	Char to blob(data),
	XML Settings(
		Stack(0),
		Row(
			"/wfs:FeatureCollection/wfs:member/omso:PointTimeSeriesObservation/om:result/wml2:MeasurementTimeseries/wml2:point"
		),
		Col(
			"/wfs:FeatureCollection/wfs:member/omso:PointTimeSeriesObservation/om:result/wml2:MeasurementTimeseries/@gml:id",
			Column Name(
				"MeasurementID"
			),
			Fill("Use Forever"),
			Type("Character"),
			Format({"Best"}),
			Modeling Type("Continuous")
		),
		Col(
			"/wfs:FeatureCollection/wfs:member/omso:PointTimeSeriesObservation/om:result/wml2:MeasurementTimeseries/wml2:point/wml2:MeasurementTVP/wml2:time",
			Column Name(
				"Timestamp"
			),
			Fill("Use Once"),
			Type("Character"),
			Format({"Best"}),
			Modeling Type("Continuous")
		),
		Col(
			"/wfs:FeatureCollection/wfs:member/omso:PointTimeSeriesObservation/om:result/wml2:MeasurementTimeseries/wml2:point/wml2:MeasurementTVP/wml2:value",
			Column Name(
				"Value"
			),
			Fill("Use Once"),
			Type("Numeric"),
			Format({"Best"}),
			Modeling Type("Continuous")
		)
	),
	XML Wizard(0),
	"text"
);

For Each Row(dt,
	:MeasurementID = Word(-1, :MeasurementID, "-");
	:Timestamp = Substitute(:Timestamp, "Z", "");
);
Column(dt, "Timestamp") &amp;lt;&amp;lt; Data Type(Numeric) &amp;lt;&amp;lt; Modeling Type(Continuous) &amp;lt;&amp;lt; Format("yyyy-mm-ddThh:mm:ss", 19, 0);


dt_split = dt &amp;lt;&amp;lt; Split(
	Split By(:MeasurementID),
	Split(:Value),
	Group(:Timestamp),
	Output Table("FMI " || location),
	Sort by Column Property
);
Close(dt, no save);

dt_split &amp;lt;&amp;lt; Delete Scripts(dt_split &amp;lt;&amp;lt; Get Table Script Names);


gb = dt_split &amp;lt;&amp;lt; Graph Builder(
	Size(857, 524),
	Show Control Panel(0),
	Variables(X(:Timestamp), Y(:humidity), Y(:pressure), Y(:temperature)),
	Elements(Position(1, 1), Line(X, Y, Legend(15))),
	Elements(Position(1, 2), Line(X, Y, Legend(16))),
	Elements(Position(1, 3), Line(X, Y, Legend(17)))
);
gb &amp;lt;&amp;lt; Save Script to Data Table("Plot");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;If you wish to see how I filled XML Wizard, you can change the &lt;CODE class=" language-jsl"&gt;XML Wizard(0),&lt;/CODE&gt; to &lt;CODE class=" language-jsl"&gt;XML Wizard(1),&lt;/CODE&gt; and run code until that point. You can then see the settings in the GUI I used. And here is some sort of explanation of what those mean&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1721224560777.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66252i066D3B26A0F5F074/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1721224560777.png" alt="jthi_0-1721224560777.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You can get quite far by just using Tall Guess&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1721224586134.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66253i5AC7F47A32954BFB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1721224586134.png" alt="jthi_1-1721224586134.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But it will miss the measurement types and you have to make those few changes I did to repeat them on all rows (you could also fill once -&amp;gt; fill rest in JMP table).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 13:59:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773593#M95490</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-07-17T13:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch data XML to JMP</title>
      <link>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773818#M95518</link>
      <description>&lt;P&gt;I tried the import XML add-in in JMP before but I got lost with it, however, now based on your explanation I understand how it works! &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;Thank you!&amp;nbsp; Also, I really appreciate that you shared the way you fetched this data using&lt;SPAN&gt;&amp;nbsp;open(char to blob(), "text")!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 08:27:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fetch-data-XML-to-JMP/m-p/773818#M95518</guid>
      <dc:creator>IloinenHamsteri</dc:creator>
      <dc:date>2024-07-18T08:27:28Z</dc:date>
    </item>
  </channel>
</rss>

