none
CHR(28) ERROR IN XML in vfp8

    Question

  • Dear Freinds,

    If I hv chr(28) in the charcter string(s) I can create cursortoxml() xml file with that string but not create cursor from xmltocursor(). Example state below:--
    Local lcStoreValue,lcXMLFilePath,myXMLString as Character
    m.lcStoreValue="Visual"+Chr(28)+Chr(28)+Chr(28)+"FoxPro"
    Create Cursor TestCursor(MyValue C(100))
    Insert into TestCursor values (m.lcStoreValue)
    m.lcXMLFilePath="C:\MyXmlFile.XML"
    *-- Creating a XML file with the value of TestCursor
    CURSORTOXML('TestCursor',[m.myXMLString],1,0,0,"1")
    *-- Encoding to ISO-8859-1
    m.myXMLString=STRTRAN(m.myXMLString,["Windows-1252" standalone="yes"],["iso-8859-1" ])
    *-- storing xmlstringvalue to XML file
    STRTOFILE(m.myXMLString,m.lcXMLFilePath)
    *-- Now Createing XMLCursor from XMLfile
    XMLTOCURSOR(m.lcXMLFilePath,'myXMLcursor',512)
    * -- ERROR Invalid character
    


    Now in view of above, if I remove CHR(28) from variable lcstorevalue I can successfuly retrieve XML value to Cursor MyXmlcursor.

    My question is why it is so? is there any ifs and buts to create xml file or any limitaion of character string...

    Awaiting yr comments

    regards
    Subhankar
    subhankar
    Wednesday, September 08, 2010 7:12 AM

Answers

  • Hi,

     

    CURSORTOXML() can create cdata.

    CURSORTOXML([crsTest],[myVar|myFile],1,8,0,[1])
    One of the optional values of param #4 is 8 and takes care that memo fields are wrapped into a cdata block.

    But...this won't do, as CHR(28) is always an invalid char, no matter if it is part of cdata or not.


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    • Proposed as answer by Tom BorgmannEditor Thursday, September 16, 2010 7:01 AM
    • Marked as answer by Martin_Xie Sunday, September 19, 2010 8:32 AM
    Thursday, September 09, 2010 10:29 AM
  • You can leave the CHR(28) in the string but you have to convert the whole string into Base64 format before storing it into XML (and back before decrypting).

    Conversion to Base64 format:

    STRCONV(YourBinaryString, 13)

    Conversion from Base64 format:

    STRCONV(YourBase64String, 14)

     

    • Marked as answer by Martin_Xie Sunday, September 19, 2010 8:31 AM
    Saturday, September 18, 2010 2:34 PM

All replies

  • CHR(28) is an invalid character for XML.

    You will need to put it in an CDATA element. I'm not sure, if CURSORTOXML () can create such an element.

     

    Wednesday, September 08, 2010 7:50 AM
  • Hi,

     

    CURSORTOXML() can create cdata.

    CURSORTOXML([crsTest],[myVar|myFile],1,8,0,[1])
    One of the optional values of param #4 is 8 and takes care that memo fields are wrapped into a cdata block.

    But...this won't do, as CHR(28) is always an invalid char, no matter if it is part of cdata or not.


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    • Proposed as answer by Tom BorgmannEditor Thursday, September 16, 2010 7:01 AM
    • Marked as answer by Martin_Xie Sunday, September 19, 2010 8:32 AM
    Thursday, September 09, 2010 10:29 AM
  • Hello

    Since it is not solve my purpose in xml as I need Chr(28) So I change my code to TextMerge code inorder to proceed fot .txt file generataion

    But still my prefer is xml file i/o txt file, so I would have been much enterprsing my workflow if I cud in xml file.

    Thanks

     

     


    subhankar
    Friday, September 17, 2010 7:13 AM
  • Hi,

    you could replace that character with a placeholder. Loop through all records and exchange that character against something less problematic like ~ or ° and after reading the xml do it the other way round.

    REPLACE ALL field1 WITH STRTRAN( field1 , CHR( 28 ) , [~] ) IN crsTest
    
    REPLACE ALL field1 WITH STRTRAN( field1 , [~] , CHR( 28 ) ) IN crsTest
    
    However this has to be done to each column that might contain this specific character.


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    Friday, September 17, 2010 7:46 AM
  • I can not use STRTRAN() , because I use  Encrypt() to encrypt the string. It will create problem while Decrypt()
    subhankar
    Saturday, September 18, 2010 5:59 AM
  • You can leave the CHR(28) in the string but you have to convert the whole string into Base64 format before storing it into XML (and back before decrypting).

    Conversion to Base64 format:

    STRCONV(YourBinaryString, 13)

    Conversion from Base64 format:

    STRCONV(YourBase64String, 14)

     

    • Marked as answer by Martin_Xie Sunday, September 19, 2010 8:31 AM
    Saturday, September 18, 2010 2:34 PM