diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f5b982a9e5..c176629bb6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,10 @@ The license applies to all entries newer than 2009-04-28. */ +2012-09-20 11:15 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * harbour/contrib/xhb/txml.prg + ! xHarbour compatibility patch from Jose F. Gimenez - thanks + 2012-09-20 00:17 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/gtwvg/crt.prg ! Fixed: regression caused by redirection of "?" command. diff --git a/harbour/contrib/xhb/txml.prg b/harbour/contrib/xhb/txml.prg index 4bc613f4aa..975b8b3595 100644 --- a/harbour/contrib/xhb/txml.prg +++ b/harbour/contrib/xhb/txml.prg @@ -340,7 +340,7 @@ CLASS TXmlDocument METHOD New( xElem, nStyle ) CONSTRUCTOR METHOD Read( xData, nStyle ) INLINE HBXML_DATAREAD( Self, xData, nStyle ) METHOD ToString( nStyle ) INLINE ::oRoot:ToString( nStyle ) - METHOD Write( fHandle, nStyle ) INLINE ::oRoot:Write( fHandle, nStyle ) + METHOD Write( fHandle, nStyle ) METHOD FindFirst( cName, cAttrib, cValue, cData ) METHOD FindFirstRegex( cName, cAttrib, cValue, cData ) @@ -349,6 +349,7 @@ CLASS TXmlDocument METHOD GetContext() HIDDEN: DATA oIterator + DATA cHeader ENDCLASS @@ -369,7 +370,14 @@ METHOD New( xElem, nStyle ) CLASS TXmlDocument CASE "N" CASE "C" ::oRoot := TXmlNode():New( HBXML_TYPE_DOCUMENT ) - ::Read( xElem, nStyle ) + IF hb_fileExists( xElem ) + ::Read( hb_MemoRead( xElem ), nStyle ) + ELSE + ::Read( xElem, nStyle ) + ENDIF + IF !Empty( ::oRoot:oChild ) .AND. ::oRoot:oChild:cName == "xml" + ::cHeader := "<=xml " + ::oRoot:oChild:cData + "?>" + ENDIF EXIT ENDSWITCH @@ -377,6 +385,28 @@ METHOD New( xElem, nStyle ) CLASS TXmlDocument RETURN Self +METHOD Write( fHandle, nStyle ) CLASS TXmlDocument + + LOCAL nResult := HBXML_STATUS_ERROR + + IF ValType( fHandle ) == "C" // It's a filename! + fHandle := FCreate( fHandle ) + IF fHandle != -1 + IF Empty( ::oRoot:oChild ) .OR. !( ::oRoot:oChild:cName == "xml" ) + IF Empty( ::cHeader ) + FWrite( fHandle, '' + hb_eol() ) + ELSE + FWrite( fHandle, ::cHeader + hb_eol() ) + ENDIF + ENDIF + nResult := ::oRoot:Write( fHandle, nStyle ) + FClose( fHandle ) + ENDIF + RETURN nResult + ENDIF + +RETURN ::oRoot:Write( fHandle, nStyle ) + METHOD FindFirst( cName, cAttrib, cValue, cData ) CLASS TXmlDocument ::oIterator := TXmlIteratorScan():New( ::oRoot ) RETURN ::oIterator:Find( cName, cAttrib, cValue, cData )