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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bad data when parsing XML

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I'm using an XML Adapter to load an XML string to a set of VFP cursors. Specifically:

Code:
loXML = CREATEOBJECT("XMLAdapter")
....
lcXML = <some XML>
loXML.LoadXML(lcXML)

This code recently crashed with an error,"XML Parse error: Invalid unicode character."

I tracked it down to an unexpected character (&#x2;) in a phone number field. After I eliminated that character, it crashed again with the same error, which this time was a &#x1C in another record. I deleted that character and all was well.

Is there any way I can tell the XML Adapter to always ignore these bad characters? I've got no control over the contents of the XML, and no way of stopping any garbage getting into it.

I know I can write some VFP code to parse the XML strings before submitting them to loXML.LoadXML, but these are huge strings, so I'm looking for a more elegant solution.

Thanks in advance.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
You might check whether you can just use STRTRAN() or CHRTRAN() to limit your XML to valid characters. That should be fast, even for very large strings.

Tamar
 
Thanks for the suggestion, Tamar. That's more or less what I had in mind if all else fails.

It's more complicated than it seems, because I'd need to remove all strings in the form &#xH; where H is a valid hex number below 0x20.

Perfectly possible, of course, but I was hoping for some way of telling the XML adapter simply to ignore anything it considers to be an invalid character.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top