Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

/b Invalid Character 1

Status
Not open for further replies.

resurgam

Programmer
Oct 11, 2005
5
GB
Hia I need your help

I have never done anything with XML before.

I retrieve from an external source a memo field containing XML data with utf-8 encoding, to convert this into a cursor I do some checks to replace & symbols to say & and replace control characters CHR(1) to CHR(31) with '' just incase.

I then do the two lines below

STRTOFILE(xmltext, "names.xml")
XMLTOCURSOR("names.xml", "XMLNames", 512)

this all works fine until a memo field the 9th one to be looped through gets the following error:

XML Parse Error: An Invalid character was found in text content.

Line 148, Position21. <fieldname>No.12 Bra

That actual line should read

<fieldname>No.12 Bradwells field</fieldname>

when you look at the source data through access it appears OK but when you look at the memo field in foxpro there is a square symbol between the a and the d.

I tried to do an MLINE and step through the ascii codes to find out what this illusive character is but all it picks up on the MLINE is <fieldname>.

Is there a way of removing all invalid xml utf-8 characters. Ore finding what this invalid character is?

Thanks

R
 

Hi Resurgam,

Can you do something like the following:

Code:
lcStr = MyCursor.MyMemo
lnPos = AT("No.12 Bra", lcStr)
? ASC(SUBSTR(lcStr, lnPos + 1, 1))

That will at least give you the ASCII code of the offending character.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
thanks that worked great it turned out to be CHR(0) what a pain, unfrtunatley I have had no control over the data coming in :-(
 

Resurgam,

If this is likely to be an on-going problem, you could perhaps filter out the CHR(0)s, like this:

lcStr = STRTRAN(MyCursor.MyMemo, CHR(0), "")

Thanks for the star, by the way.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
We have an app where most Internet communication is wrapped in XML. To get past the illegal ASCII char issue we do a BASE64 conversion to convert the illegal ASCII chars in the XML stream.

lsSendWhat = STRTRAN(STRCONV(lsSendWhat, 13),'+','%2B')

Perhaps that would work for you?

Good luck

Ralph Kolva

 
Here are the 5 XML entities which may need some sort of conversion or exception handling:

& ... &amp;
" ... &quot;
' ... &apos;
< ... &lt;
> ... &gt;
 
thanks mike

Thats exactly what I have done I have also got in touch with the people sending me the xml and asked them to put some validation on at their end too :)

Thanks DBMARK already got conversions in for that but it took me some time to find anywhere that told me about having to do it. it is good you have pointed it out in here.

Rach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top