Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

extracting and parsing data from text

Posted 30 Apr 2005 08:10:00
1
has voted
30 Apr 2005 08:10:00 Dan Berdusco posted:
i have a scenario where I download daily some currency rates from a website so that I can have up-to-date currency exchange on my site. Each day, i download some information, but I have yet to figure out how to extract certain parts of the data out of the file.

For example, the data that I receive looks like this:

<pre id=code><font face=courier size=2 id=code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;

&lt;!DOCTYPE xe-datafeed [
&lt;!ELEMENT xe-datafeed (header*,currency*)&gt;
&lt;!ELEMENT header (hname,hvalue)&gt;
&lt;!ELEMENT hname (#PCDATA)&gt;
&lt;!ELEMENT hvalue (#PCDATA)&gt;
&lt;!ELEMENT currency (csymbol,cname,crate)&gt;
&lt;!ELEMENT csymbol (#PCDATA)&gt;
&lt;!ELEMENT cname (#PCDATA)&gt;
&lt;!ELEMENT crate (#PCDATA)&gt;
]&gt;

&lt;xe-datafeed&gt;
&lt;header&gt;&lt;hname&gt;Version&lt;/hname&gt;&lt;hvalue&gt;2.45&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Status&lt;/hname&gt;&lt;hvalue&gt;OK&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Current UTC Time&lt;/hname&gt;&lt;hvalue&gt;2005.04.28 16:22:30&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Notice&lt;/hname&gt;&lt;hvalue&gt;All use of this data is strictly regulated under the licensing Agreement. Unauthorized use is a breach of your duties and responsibilities under this Agreement.&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Feed Expires on&lt;/hname&gt;&lt;hvalue&gt;April 19 2006&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Days Remaining&lt;/hname&gt;&lt;hvalue&gt;356&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;UTC Time of Your Next Update&lt;/hname&gt;&lt;hvalue&gt;2005.04.29 12:00:00&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Seconds Until Your Next Update&lt;/hname&gt;&lt;hvalue&gt;70650&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Rate Format&lt;/hname&gt;&lt;hvalue&gt;XML&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Rate Type&lt;/hname&gt;&lt;hvalue&gt;DAILY&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Permitted accesses per week&lt;/hname&gt;&lt;hvalue&gt;9&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Accesses so far this week&lt;/hname&gt;&lt;hvalue&gt;4&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Accesses remaining in this week&lt;/hname&gt;&lt;hvalue&gt;5&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Days until new access period begins&lt;/hname&gt;&lt;hvalue&gt;3&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;UTC Timestamp&lt;/hname&gt;&lt;hvalue&gt;2005.04.28 12:00:00&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Local Timezone&lt;/hname&gt;&lt;hvalue&gt;UTC&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Local Timestamp&lt;/hname&gt;&lt;hvalue&gt;2005.04.28 12:00:00&lt;/hvalue&gt;&lt;/header&gt;
&lt;header&gt;&lt;hname&gt;Base Currency&lt;/hname&gt;&lt;hvalue&gt;CAD&lt;/hvalue&gt;&lt;/header&gt;
&lt;currency&gt;&lt;csymbol&gt;AUD&lt;/csymbol&gt;&lt;cname&gt;Australia Dollars&lt;/cname&gt;&lt;crate&gt;1.0278093731&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;CAD&lt;/csymbol&gt;&lt;cname&gt;Canada Dollars&lt;/cname&gt;&lt;crate&gt;1.0000000000&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;CHF&lt;/csymbol&gt;&lt;cname&gt;Switzerland Francs&lt;/cname&gt;&lt;crate&gt;0.9530380354&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;EUR&lt;/csymbol&gt;&lt;cname&gt;Euro&lt;/cname&gt;&lt;crate&gt;0.6188866472&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;GBP&lt;/csymbol&gt;&lt;cname&gt;United Kingdom Pounds&lt;/cname&gt;&lt;crate&gt;0.4192512854&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;INR&lt;/csymbol&gt;&lt;cname&gt;India Rupees&lt;/cname&gt;&lt;crate&gt;34.9346500799&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;JPY&lt;/csymbol&gt;&lt;cname&gt;Japan Yen&lt;/cname&gt;&lt;crate&gt;84.6248555640&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;NZD&lt;/csymbol&gt;&lt;cname&gt;New Zealand Dollars&lt;/cname&gt;&lt;crate&gt;1.0998550822&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;USD&lt;/csymbol&gt;&lt;cname&gt;United States Dollars&lt;/cname&gt;&lt;crate&gt;0.7992918639&lt;/crate&gt;&lt;/currency&gt;
&lt;currency&gt;&lt;csymbol&gt;ZAR&lt;/csymbol&gt;&lt;cname&gt;South Africa Rand&lt;/cname&gt;&lt;crate&gt;4.8999331241&lt;/crate&gt;&lt;/currency&gt;
&lt;/xe-datafeed&gt;
</font id=code></pre id=code>

What I need to do, is extract certain rates (CAD, USD, and EURO) from the data and store them in variables so that I can use them with other applications.

My question is, does ASP have a built in function or some way to sort or parse this information, so that i CAN store certain portions in variables? Or does any one know any way to do this at all?

Any and all help is appreciated.

Thanks in advance.

Edited by - flexman44 on 30 Apr 2005 08:11:40

Replies

Replied 30 Apr 2005 19:07:39
30 Apr 2005 19:07:39 Chris Charlton replied:
I doubt ASP3 has a set of functions for this, but I may be wrong (*someone chime in*), since I would think ASP.NET is prepared for this. In regular ASP3, you could do string matching, but if you can find a mudule/component that allows you to parse in the whole XML file and pick out (easily) what you want, that's the way to go!

~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replied 03 May 2005 09:10:26
03 May 2005 09:10:26 Dan Berdusco replied:
Anybody want to offer some help on the .NET side of things. I am quite .NET illiterate.

Thank so much!

Edited by - flexman44 on 03 May 2005 09:10:57

Reply to this topic