Extracting info from an XML file

garcon

Well-known member
Joined
Dec 13, 2004
Messages
47
Programming Experience
Beginner
Folks,

I need to extract some information from an XML file - specifically a number between the tags:

<fx-rate>1.23456789</fx-rate>

Does anyone know how to do this exactly?

Cheers,
G.
 
VB.NET:
Expand Collapse Copy
dim xmldoc as new xmldocument()
xmldoc.load("your xml file")
dim nodelist as xmlnodelist
dim nodes as xmlnode
nodelist=xmlnoc.getelementsbytag("fx-rate")
for each nodes in nodelist
messagebox.show(node.innertext)
next

TPM
 
Guys - thanks for th comments - much appreciated. Unfortunately the XML file is more complex than originally anticipated. It gives a base currency and a foreign currency and also specifies 3 ranges. check this out:

<base ="eur">
<foreign="gbp">
<base-value min="0.000" max="99.999">
<fx-rate>0.123</fx-rate>
<base-value min="100.000" max="1000.000">
<fx-rate>0.456</fx-rate>
<base-value min="1000.001" max="999999999999999.999">
<fx-rate>0.789</fx-rate>
...etc...

So I'll have to extract each base and foreign value. Compare to my 2 originals. If they match then I have to extract the ranges and compare to my value. Depending ion what this is I the extract the correct fx value.
Sound fairly mucky doesn't it?

Comments/Suggestions anyone?
Cheers,
G.
 
The text you have shown is not a well formatted XML file as far I I know.
When I try to open this with any XML viewer, it gives errors.
First, <base ="eur"> is incorrect. For a well formatted file it should be something like <base name="eur">.
Also the base-value nodes aren't ended (</base-value>)
 
You could use the ReadXML function of a dataset to fill a dataset with the XML file.
For me it's easier to manipulate a dataSet.

The reason I pointed out the formatting was that the ReadXML function will error if the XML is not well formatted.
 
I have tags in the form:

<foreign iso-alpha="GBP">
<break min="0.000" max="100.00" rate="0.667843">
<break min="100.001" max="9999.999" rate="0.683435>

How the hell do I extract these?

Confused,
G.
 
Last edited:
Back
Top