FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour INeed to read an xml that contains some strange char
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
INeed to read an xml that contains some strange char
Posted: 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 (xml): Select all Collapse
<div class="xml" id="{CB}" style="font-family: monospace;">
<?xml version="1.0" encoding="utf-8"?>
<SERVICE_TYPES>
   <item>
      <SERVICE_TYPE>2002</SERVICE_TYPE>
      <DESCRIPTION>OSS – BULK REPAIR</DESCRIPTION>
   </item>
</SERVICE_TYPES>
 </div>


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 (xml): Select all Collapse
<div class="xml" id="{CB}" style="font-family: monospace;">
   <item>
      <SERVICE_TYPE>1102</SERVICE_TYPE>
      <DESCRIPTION>SWAP-OPTICAL ENGINE(EEE)</DESCRIPTION>
   </item>
 </div>


Many thanks
Marco Boschi
info@marcoboschi.it
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: INeed to read an xml that contains some strange char
Posted: 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
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: INeed to read an xml that contains some strange char
Posted: 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

Marco Boschi
info@marcoboschi.it
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: INeed to read an xml that contains some strange char
Posted: 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 (fw): Select all Collapse
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
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: INeed to read an xml that contains some strange char
Posted: Tue Apr 04, 2017 01: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

Marco Boschi
info@marcoboschi.it
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: INeed to read an xml that contains some strange char
Posted: Tue Apr 04, 2017 02:03 PM

Solved!
I'm waiting a for a file without those characters
Bye

Marco Boschi
info@marcoboschi.it
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: INeed to read an xml that contains some strange char
Posted: Wed Apr 05, 2017 07: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.

Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: INeed to read an xml that contains some strange char
Posted: Thu Apr 06, 2017 07:39 AM

8)

Marco Boschi
info@marcoboschi.it

Continue the discussion