473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Read Xml data problem

Hi all, this is my first post, i have a little problem.

I'm tryign to read a specific atribute from a xml website using this code:

...
Expand|Select|Wrap|Line Numbers
  1. 'this is the url im trying to read, tmpIn is a string that complete the url:
  2. Dim url As String = "http://maps.google.com/maps/geo?q=" & tmpIn & "&output=xml"
  3.  
  4. Dim reader As New XmlTextReader(url)
  5.  
  6. reader.WhitespaceHandling = WhitespaceHandling.Significant
  7.  
  8. While (reader.Read())
  9.         'now i try to read the atribute coordinates from the url to a string tmpLatLong:
  10.             If reader.Name.ToString() = "coordinates" Then
  11.                 tmpLatLong = reader.ReadString().ToString()
  12.             End If
  13.  
  14.  End While
  15.  
...

The problem is tmpIn takes diferents values (string) when the function is used and sometimes this works, and othertimes it gives an error (Invalid character in the given encoding. Line 9, position 15.), but is not because of the url, is when it tries to read the coordinates... any ideas how can i fix this? or change to a better code? any help is welcome..

thx in advance
Mar 26 '09 #1
7 2230
tlhintoq
3,525 Expert 2GB
So what you're saying is if the TempIn is properly formated as Coordinates the function works, but if the TempIn is not properly formatted then the function fails?

Do I understand that right?
Mar 26 '09 #2
@tlhintoq
the coordinates is given by the website, they depend of the TempIn value, but i dont know why it fails, for example if TempIn="canedo,santa maria da feira, portugal" (its a valid adress) it works fine, but if it is TempIn="lobao, santa maria da feira, portugal" (its a valid adress too) it doesnt work and gives that error (Invalid character in the given encoding. Line 9, position 15.) but i checking the website i dont see any cause that could make it happen, and i see the coordinates there with a valid value :S
Mar 26 '09 #3
tlhintoq
3,525 Expert 2GB
Ok... Check that I have this right..

You feed the URL to XMLTextReader, which received an XML page back based on the location you give it in the TempIn variable.
When you get the whole XML page back as a reply that goes into the While loop.
When the While loop finally finds a tag of "coordinates" it assigns them to tmpLatLong.

But sometimes it goes awry... at you get an error in line 9, position 15.

So what does line 9 of the response look like in a good value and what does line 9 of a bad run look like? What is at position 15 of the bad value?
Mar 26 '09 #4
tlhintoq
3,525 Expert 2GB
I do notice that
http://maps.google.com/maps/geo?q=ca...gal&output=xml
Gives a response where no characters have accented characters in it.
canedo,santa maria da feira, portugal 200 geocode Canedo, Santa Maria da Feira, Portugal PTPortugalAveiroSanta Maria da FeiraCanedo -8.4630566,41.0118083,0

http://maps.google.com/maps/geo?q=lo...gal&output=xml
On the other hand does have accented a with tilde over it in a couple places.
lobao, santa maria da feira, portugal 200 geocode Lobão, Santa Maria da Feira, Portugal PTPortugalAveiroSanta Maria da FeiraLobão -8.4894589,40.9842033,0

I would bet those are your illegal characters.
Mar 26 '09 #5
@tlhintoq
yes is how you say :)

well, for example of a non working case, where line 9 is:
Expand|Select|Wrap|Line Numbers
  1. <address>Lobão, Santa Maria da Feira, Portugal</address>
where in the line 21 i have
Expand|Select|Wrap|Line Numbers
  1. <coordinates>-8.4894589,40.9842033,0</coordinates>
that is the information i need...
idk if it is bcause of the char "ã", but i cant change that.

a working case would be like:
Expand|Select|Wrap|Line Numbers
  1. <address>Canedo, Santa Maria da Feira, Portugal</address>
and in line 21
Expand|Select|Wrap|Line Numbers
  1. <coordinates>-8.4630566,41.0118083,0</coordinates>
but im not sure if that kind of characters are the cause of the error
Mar 26 '09 #6
@tlhintoq
maybe, but how i ignore that?
Mar 26 '09 #7
Ok i fixed the problem :D

i added to the url &oe=utf-8, looking like this:
Dim url As String = "http://maps.google.com/maps/geo?q=" & tmpIn & "&output=xml&oe=utf-8"

and solved my problem.

Thx for the help :)
Mar 26 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

75
by: Greg McIntyre | last post by:
I have a Python snippet: f = open("blah.txt", "r") while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit...
24
by: Bob Alston | last post by:
Anyone know a way to make all access to a linked table, in another Access MDB, read only? I really don't want all the hassle of implementing full access security. I can't do this at the server...
7
by: Mike | last post by:
Hi, I have an iteration to retrieve a number of messages from a server. Within this iteration, I am using the following code: do { readBytes = base.GetStream().Read(received, 0,...
9
by: wscrsurfdude | last post by:
f = open('myfile,'r') a = f.read(5000) When I do this I get the first 634 bytes. I tried using the: f = open('myfile,'rb') option, but now there are a few 0x0D bytes extra in myfile. 0x0D =...
2
by: ShawnD | last post by:
I'm having some issues when trying to read input off of a pipe using a python script. I'm trying to process packet data from tcpdump in real-time, so it's a filter that needs to read data while the...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
2
by: agphoto | last post by:
There is big or problem in open file in read and write mode.. $file = "data.txt"; $fp = fopen($file,"w+"); $line = fgets($fp,"120"); // i need only 1st line to read and upto 120 bytes echo...
8
by: dosworldguy | last post by:
I have been having a very peculiar issue from a long time. I have an application where multiple clients read from a shared set of files. When a record is changed, sometimes the win9x clients...
7
by: Tracks | last post by:
I have old legacy code from vb5 where data was written to a file with a variant declaration (this was actually a coding error?)... in vb5 the code was: Dim thisdata as integer Dim thatdata...
3
by: phwashington | last post by:
I am new to C++ and have a data file I want to read, which was stored in binary. I have looked at the data with a hex editor and it appears to be correct. Whenever I try to read it though as an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.