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:
... -
'this is the url im trying to read, tmpIn is a string that complete the url:
-
Dim url As String = "http://maps.google.com/maps/geo?q=" & tmpIn & "&output=xml"
-
-
Dim reader As New XmlTextReader(url)
-
-
reader.WhitespaceHandling = WhitespaceHandling.Significant
-
-
While (reader.Read())
-
'now i try to read the atribute coordinates from the url to a string tmpLatLong:
-
If reader.Name.ToString() = "coordinates" Then
-
tmpLatLong = reader.ReadString().ToString()
-
End If
-
-
End While
-
...
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
7 2230
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?
@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
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?
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.
@tlhintoq
yes is how you say :)
well, for example of a non working case, where line 9 is: - <address>Lobão, Santa Maria da Feira, Portugal</address>
where in the line 21 i have - <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: - <address>Canedo, Santa Maria da Feira, Portugal</address>
and in line 21 - <coordinates>-8.4630566,41.0118083,0</coordinates>
but im not sure if that kind of characters are the cause of the error
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 :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |