FIX: The CDATA Section of CURSORTOXML May Format Characters Incorrectly (318977)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 7.0

This article was previously published under Q318977

SYMPTOMS

When the nFlag parameter is set to 8 in the CURSORTOXML function in a memo field, the following characters may be formatted incorrectly:
  • less than (<)
  • greater than (>)
  • ampersand (&)

RESOLUTION

To resolve this problem, obtain the latest service pack for Visual FoxPro for Windows 7.0. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

316964 How to Obtain the Latest Visual FoxPro for Windows 7.0 Service Pack

STATUS

Microsoft has confirmed that this is a problem in Microsoft Visual FoxPro for Windows 7.0.

This problem was first corrected in Visual FoxPro for Windows 7.0 Service Pack 1.

MORE INFORMATION

When you set the nFlag parameter to 8 in the CURSORTOXML function, the contents of the memo field with an XML CDATA section wrap. This protects the data if the <, >, or & characters are used in the memo field. These characters are not formatted correctly in the memo field when the CURSORTOXML function is used in the original release version of Visual FoxPro 7.0.

Steps to Reproduce Behavior

Paste the following code into a program file, and then run the file from the Command window:
CLEAR 
CREATE CURSOR myxml_memo (fld_memo M)
APPEND BLANK
REPLACE fld_memo WITH "Joe & Jim's last name is <Smith>."
CURSORTOXML("myxml_memo", "myxml_var1", 1, 8)

* Displays CDATA section with the &amp, &lt, and &gt substitutions.
? myxml_var1
myxml_var2 = STRTRAN(myxml_var1, "&" + "amp;", "&")
myxml_var2 = STRTRAN(myxml_var2, "&" + "lt;", "<")
myxml_var2 = STRTRAN(myxml_var2, "&" + "gt;", ">")
*!* Note: the strings in the code are broken up for clarity.
*!* You can write them as one literal in your code.

* The CDATA section should resemble the following:
? myxml_var2
LOCAL ox AS MSXML2.DomDocument.3.0
ox = NEWOBJECT("MSXML2.DomDocument.3.0")
ox.Async = .F.
ox.LoadXML(myxml_var1)
? ox.DocumentElement.FirstChild.FirstChild.Xml
* This is displayed incorrectly in the MSXML text.
? ox.DocumentElement.FirstChild.FirstChild.Text
? ""
ox.LoadXML(myxml_var2)
? ox.DocumentElement.FirstChild.FirstChild.Xml
* This is expected when you use CDATA to wrap the text.
? ox.DocumentElement.FirstChild.FirstChild.Text
				

Modification Type:MajorLast Reviewed:3/27/2002
Keywords:kbbug kbCodeSnippet kbCtrl kbDSupport kbVFP700sp1fix KB318977