xml

Get location (Latitude & Longitude) for given address in c# using google api

In my application I wanted to find Latitude & Longitude of address of a person.

To do this I have used google api.

Bellow is c# code:

Here What I did is just called google service & just extracted the latitude & longitude from the xml response which I got from service.

This free service has limitation of 2500 request per IP per day, so If your application is will request more than that then google api will block your IP temporarily & If you continue to do this then It may ban your IP also.

I your application will request more that 2500 request per day per IP then you may have to buy service from google.

How to read XML attributes using XPath in c#

In Previous tutorial I showed that how can we read xml node data using XPath
Now we will read attributes data from XML using XPath
Bellow is demo XML file from which we will read XML attribute data.

As shown in previous tutorial we need to load document, then read root node & then read node which we want to read.

Now we will read attribute from node “name”

In above code what we do is that we define condition that if node “name” has attribute & attribute “firstname” is not null then get the data from that attribute else pass empty string.
Like this we can read data for attribute “lastname” also.

How to read data from XML using XPath

Let’s say I want to read bello XML File using XPath

To read this XML first we need to load this document , which can be done as foolows

After loading the xml file we need to give root node name & after that we need to find nodes in that root node.
This can be done as follows

Like this we can read data from xml using XPath

How to Read xml file using Xpath in C#

Hi

Here i will show you how to read the xml file using Xpath in the C#

Here is the XML file which i have used…

(please remove the spaces from above XML File)

I have used simple Console Application Which reads this XML File & stores data in the list …

Hope it helps ….

Export xml data into text file

If you want to export attributes from XML file to text file then you just have to read that attribute from xml & write it in text file…I have shown hoe to write string into text file Here ….

Here is full code….Here i have used other way to write string into text file ie. WriteAllText function…

 Scroll to top