INeed to read an xml that contains some strange char

INeed to read an xml that contains some strange char

Postby MarcoBoschi » Tue Apr 04, 2017 11:06 am

Hi,
I found some strange characters in a xml file that I have to read to populate a dbf table.
I'm sure that the person who typed in his program insert this

OSS - BULK REPAIR
and not this
OSS – BULK REPAIR

but unfortunately his export program create this xml

Code: Select all  Expand view

<?xml version="1.0" encoding="utf-8"?>
<SERVICE_TYPES>
   <item>
      <SERVICE_TYPE>2002</SERVICE_TYPE>
      <DESCRIPTION>OSS – BULK REPAIR</DESCRIPTION>
   </item>
</SERVICE_TYPES>
 


And I have to read it for populate my dbf table

How can I transform xml file in order to obtain (for instance)

OSS - BULK REPAIR
and not
OSS – BULK REPAIR


This is another piece of the same xml you can note that there are not strange characters

Code: Select all  Expand view

   <item>
      <SERVICE_TYPE>1102</SERVICE_TYPE>
      <DESCRIPTION>SWAP-OPTICAL ENGINE(EEE)</DESCRIPTION>
   </item>
 


Many thanks
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: INeed to read an xml that contains some strange char

Postby cnavarro » Tue Apr 04, 2017 11:22 am

Try with hb_StrToUtf8
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: INeed to read an xml that contains some strange char

Postby MarcoBoschi » Tue Apr 04, 2017 12:08 pm

I've tried but ...nothing!
I've just asked to my partner why there are these characters.
The presence of these characters in a field in a table dbf can cause problems
Many thanks
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: INeed to read an xml that contains some strange char

Postby Rick Lipkin » Tue Apr 04, 2017 12:46 pm

Marco

Just a quick thought .. if you know what you are looking for, could you not use the StrTran() function to locate and replace them out of your text ?

Code: Select all  Expand view

cDesc := "OSS – BULK REPAIR"

cText := StrTran( cDesc, "–", "-")   // cText should resolve down to "OSS - BULK REPAIR"
 


The above code is not that elegant, but should give you the result you are looking for ..

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: INeed to read an xml that contains some strange char

Postby MarcoBoschi » Tue Apr 04, 2017 1:05 pm

Yes Rick,
I my opinion a field that contains "OSS - BULK REPAIR" and another that contains "OSS ÔÇô BULK REPAIR"
field->codice = "OSS - BULK REPAIR"
field->descri = "OSS ÔÇô BULK REPAIR"
? field->codice <> field->descri
I hoped was a problem related to unicode or something like that

I wait the response of their programmer
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: INeed to read an xml that contains some strange char

Postby MarcoBoschi » Tue Apr 04, 2017 2:03 pm

Solved!
I'm waiting a for a file without those characters
Bye
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: INeed to read an xml that contains some strange char

Postby reinaldocrespo » Wed Apr 05, 2017 7:11 pm

For what's worth, for that type of situation I usually recur to the CharOnly() function.

CharOnly()
Removes all characters but the specified ones from a string

Syntax
CharOnly( <cRemaining>, <cString> ) --> cResult

Arguments
<cRemaining>
This character string defines the characters that are to remain in the result string.
<cString>
This is the character string to process. Return
The function removes all characters from <cString> except those contained in <cRemaining> and returns the result.

So in this case you could simply say:

cText := CharOnly( [ABCDEFGHJKLMNOPQRSTVWXYZ0123456789-abcdefghijklmnopqrstvwxyz], cText )

Hope that helps.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: INeed to read an xml that contains some strange char

Postby MarcoBoschi » Thu Apr 06, 2017 7:39 am

8)
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 77 guests