Page 1 of 1

DcXml Encoding options

Posted: Fri Feb 07, 2020 11:29 am
by PedroAlex
Roger,

DcXml it is a great tool and I use it very often.

sometimes I need to change the encoding.
however the function DC_XmlNode:WriteXML is predefined to use "windows-1252".

I sugest this improvement for this Method (if you agree):

Code: Select all

METHOD DC_XmlNode:WriteXML( cFileName, lCanon, lSuppressIndent, nOption )

LOCAL nHandle
nHandle := FCreate(cFileName)
IF nHandle <= 0
  RETURN .F.
ENDIF
IF nOption == 1
    FWrite(nHandle,'<?xml version="1.0" encoding="UTF-8"?>'+CRLF)
ELSE
	FWrite(nHandle,'<?xml version="1.0" encoding="windows-1252"?>'+CRLF)
ENDIF
::writeNode( nHandle,lCanon,lSuppressIndent)
FClose(nHandle)

RETURN .T.
Or you have another solution?

Thanks..

Re: DcXml Encoding options

Posted: Fri Feb 07, 2020 1:29 pm
by rdonnay
Yes, I agree.

I made the change to my source code.

BTW - The original code WAS UTF-8.

Re: DcXml Encoding options

Posted: Sun Feb 09, 2020 1:16 am
by messaoudlazhar
I suggest function to this :

Code: Select all

METHOD DC_XmlNode:WriteXML( cFileName, lCanon, lSuppressIndent, cEncodage )

LOCAL nHandle
DEFAULT cEncodage TO 'UTF-8'
nHandle := FCreate(cFileName)
IF nHandle <= 0
  RETURN .F.
ENDIF
FWrite(nHandle,'<?xml version="1.0" encoding="'+cEncodage+'"?>'+CRLF)
::writeNode( nHandle,lCanon,lSuppressIndent)
FClose(nHandle)

RETURN .T.

Re: DcXml Encoding options

Posted: Sun Feb 09, 2020 8:11 am
by rdonnay
That's better.