I'm using the xignite API to get real time currency exchange data. When I use my query string:
http://globalcurrencies.xignite.com/xGlobalCurrencies.xml/GetRealTimeRate?Symbol=GBPEUR&_token=[mytoken]
I get the following:
<Rate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.xignite.com/services/">
<Outcome>Success</Outcome>
<Identity>Request</Identity>
<Delay>0.0218855</Delay>
<BaseCurrency>USD</BaseCurrency>
<QuoteCurrency>EUR</QuoteCurrency>
<Symbol>USDEUR</Symbol>
<Date>08/24/2016</Date>
<Time>3:23:34 PM</Time>
<QuoteType>Calculated</QuoteType>
<Bid>0.889126</Bid>
<Mid>0.88915</Mid>
<Ask>0.889173</Ask>
<Spread>4.74352E-05</Spread>
<Text>
1 United States dollar = 0.88915 European Union euro
</Text>
<Source>Rate calculated from EUR:USD</Source>
</Rate>
I'm trying to access the contents of the Mid
element and so far I'm doing this
var xDoc = XDocument.Load(
"http://globalcurrencies.xignite.com/xGlobalCurrencies.xml/GetRealTimeRate?Symbol="
+ "GBP" + "EUR" + "&_token=[MyToken]");
string s = (string)xDoc.Root.Element("Mid");
output.Text = s;
The xDoc
variable returns with the XML that I showed previously, but when I try to get the contents of the Mid
element, string s
is null
. How do I access the contents of the element Mid
using XDoc?
I use Linq to XML, here is an example
myObjects will contain an array of MyObjects from the XML file.
Edit: since you updated your question with the XML, I think you are only missing the namespace on the query (the ns on my query), please take a look on Charles Mager answer
My answer is a different approach.. you save the Rate object and the use it without the need to read the XML again (you would need to define the Rate in a class) Be careful with the value conversions I did, you would need to match yourclass :)