create XML

1,350 views
Skip to first unread message

Paola Bruccoleri

unread,
Jul 2, 2013, 10:30:44 AM7/2/13
to Lista Harbour-users
Hello
Should I create an XML a little big.
Does anyone have any class or function to facilitate the work and not
having to go creating the tag string?

Thanks a lot!

M., Ronaldo

unread,
Jul 2, 2013, 12:45:23 PM7/2/13
to harbou...@googlegroups.com
Hi Paola !


Did you try "hbmxml.ch"

...\contrib\hbmxml\tests



Regards

DaNiEl MaXiMiLiAnO

unread,
Jul 2, 2013, 10:55:14 AM7/2/13
to harbou...@googlegroups.com
Hola Paola :
             si tu necesidad es trabajar con XML  puedes mirar este gran aporte
de Rathinagiri en www.hmgforum.com
esta publicado en Sourceforge : http://sourceforge.net/projects/xbrliant/?source=dlp
y lo que necesitas esta en C:\Temp\XBRLiant_1.01_Beta_Source\exportinstance.Prg

 
Saludos
                DaNIEl MaXiMiLiAnO


De: Paola Bruccoleri <pbruc...@adinet.com.uy>
Para: Lista Harbour-users <harbou...@googlegroups.com>
Enviado: martes, 2 de julio de 2013 11:30
Asunto: [harbour-users] create XML
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-users+unsub...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Paola Bruccoleri

unread,
Jul 2, 2013, 7:20:28 PM7/2/13
to Lista Harbour-users
El 02/07/2013 11:30, Paola Bruccoleri escribi�:
Hello!

how compile this sample? C:\harbour\contrib\hbmxml\tests\custom.prg

I have harbour 3.2 (win8 64b)

I set:
SET PATH=f:\hb32\bin;f:\hb32\comp\mingw\bin

and then:
hbmk2 hbmk.hbm

and I get this error:

f:\harbour-3.2.0\contrib\hbmxml\tests>hbmk2 hbmk.hbm
hbmk2: Processing local make script: hbmk.hbm
f:\hb32\comp\mingw\bin\nm.exe:
'C:/Users/Paola/AppData/Local/Temp/hbmk_3mf2rr.di
r/.c': No such file

Very thanks!
byeeeeeeeee



Gmail

unread,
Jul 3, 2013, 2:37:44 AM7/3/13
to harbou...@googlegroups.com
You just have to do this: hbmk2 custom

hbmk.hbm will be called automatically.

I strongly suggest you to do the following to understand what hbmk2 can do
and for what is hbmk.hbm

Type: hbmk2 --longhelp >manual.txt
Now open manual.txt and look for hbmk.hbm
If you have problems to open Linux files under Windows I suggest you to look
for XPad: http://www.mcrenox.com.ar/xpad/
It's a notepad replacement with many advantages. It's very small and works
well. No installation required (690Kb)

There it says:
hbmk.hbm is an optional .hbm file residing in current working directory,
which gets automatically processed before other options

I hope it will help you.

Regards,

Qatan

Paola Bruccoleri

unread,
Jul 3, 2013, 12:53:26 PM7/3/13
to Lista Harbour-users
Hello everyone
Thanks for your tips.

DanielMaximiliano: the example that tells me this based on the contribution that I intend to try; anyway you take this source.

I execute:
PATH=f:\HB32\BIN (here is nightly version 3.2.0dev rev. 18847)

in the directory F:\harbour-3.2.0\contrib\hbmxml\tests
hbmk2 custom.prg

BUT.... I have an error when execute the sample: argment error!
(the sources are in the directory harbour-3.2.0, the binary in f:\hb32)




What is the problem? the sample is old?
very thanks!




M., Ronaldo

unread,
Jul 3, 2013, 1:59:24 PM7/3/13
to harbou...@googlegroups.com
// Just a Sample for use:

#include "hbmxml.ch"

// *---------------------------------------------------------------------------*
// F_XML_Create()
// Create a sample XML : Use array for each element on tree
// *---------------------------------------------------------------------------*
FUNCTION F_XML_Create()

   LOCAL cAux
   LOCAL cFile := 'SAMPLE.XML'
   LOCAL aNode := Afill( Array( 16 ), '' )
   LOCAL oDoc := mxmlNewXML( "1.0" )

   // Create main XML node
   aNode[ 1 ] := mxmlNewElement( oDoc, "NfseToSend" )

   // Create XML node
   aNode[ 2 ] := mxmlNewElement( aNode[ 1 ], "Rps" )

   // Create XML node
   aNode[ 3 ] := mxmlNewElement( aNode[ 2 ], "InfDeclService" )

   // Create XML node
   aNode[ 4 ] := mxmlNewElement( aNode[ 3 ], "Rps" )

   // Create XML node
   aNode[ 5 ] := mxmlNewElement( aNode[ 4 ], "IdRps" )

   aNode[ 6 ] := mxmlNewElement( aNode[ 5 ], "Number" )
   cAux := '12345678'
   mxmlNewText( aNode[ 6 ], 0, cAux )

   aNode[ 6 ] := mxmlNewElement( aNode[ 5 ], "Serie" )
   cAux := 'UNICA'
   mxmlNewText( aNode[ 6 ], 0, cAux )

   aNode[ 6 ] := mxmlNewElement( aNode[ 5 ], "Tipe" )
   cAux := '1'
   mxmlNewText( aNode[ 6 ], 0, cAux )

   aNode[ 5 ] := mxmlNewElement( aNode[ 4 ], "Date" )
   cAux := hb_TSToStr( hb_DateTime() )
   mxmlNewText( aNode[ 6 ], 0, cAux )
 
   aNode[ 5 ] := mxmlNewElement( aNode[ 4 ], "Status" )
   cAux := '1'
   mxmlNewText( aNode[ 6 ], 0, cAux )

   // write the XML tree
   cAux :=  mxmlSaveFile( oDoc, cFile, MXML_NO_CALLBACK )

   RETURN( NIL )

"José M. C. Quintas"

unread,
Jul 3, 2013, 4:26:24 PM7/3/13
to harbou...@googlegroups.com
I use functions for each block and XmlTag(), anything like this:

PROCEDURE Main
LOCAL cXml

USE filename
cXml := [< filename id="] + Alias() + [">]
XmlRecords( @cXml )
cXml += [</filename>]
? cXml
RETURN

STATIC FUNCTION XmlRecords( cXml )
DO WHILE .NOT. Eof()
cXml += XmlTag( "record", XmlFields() )
SKIP
ENDDO
RETURN NIL

FUNCTION XmlFields( cXml )
cXml += XmlTag( FieldName(1), FieldGet(1) )
cXml += XmlTag( FieldName(2), FieldGet(2) )
RETURN NIL

FUNCTION XmlTag( cNode, cValue )
LOCAL cText
cText := "<" + cNode + ">" + cValue + "</" + cNode + ">"
RETURN cText

Jos� M. C. Quintas

M., Ronaldo

unread,
Jul 3, 2013, 4:59:48 PM7/3/13
to harbou...@googlegroups.com
Hi José !

hbmxml provide a easy way to work with XML files/schemas ( full compliant with XML standards )

I think you have a very hard work when need to read/create XML data ( NFe, CTe, xbrl taxonomy, etc... )
Give a try to MiniXML and you will like it

regards

"José M. C. Quintas"

unread,
Jul 3, 2013, 10:08:17 PM7/3/13
to harbou...@googlegroups.com
I don't consider this as an hard work, it's only another way to work
with xml.
I prefer to use in this way, code is cleaner for me.
As example, this is part of my code to get emitente data from NFe:

mXmlNode1 = XmlNode( XmlInput, "emit" )
oNfe:Emitente:Cnpj = Transform( XmlNode( mXmlNode1, "CNPJ" ), "@R
99.999.999/9999-99" )
oNfe:Emitente:Nome = Upper( XmlNode( mXmlNode1, "xNome" ) )
oNfe:Emitente:InscricaoEstadual := XmlNode( mXmlNode1, "IE" )
mXmlNode2 = XmlNode( mXmlNode1, "enderEmit" )
oNfe:Emitente:Endereco := Upper( XmlNode( mXmlNode2, "xLgr" ) )
oNfe:Emitente:Numero := XmlNode( mXmlNode2, "nro" )
oNfe:Emitente:Compl := XmlNode( mXmlNode2, "xCpl" )
oNfe:Emitente:Bairro := Upper( XmlNode( mXmlNode2,
"xBairro" ) )
oNfe:Emitente:CidadeIbge := XmlNode( mXmlNode2, "cMun" )
oNfe:Emitente:Cidade := Upper( XmlNode( mXmlNode2, "xMun" ) )
oNfe:Emitente:Uf := Upper( XmlNode( mXmlNode2, "UF" ) )
oNfe:Emitente:Cep := Transform( XmlNode( mXmlNode2,
"CEP" ), "@R 99999-999" )
oNfe:Emitente:Telefone := XmlNode( mXmlNode2, "fone" )

XmlNode() is anything like this, inverse of XmlTag():

FUNCTION XmlNode( cXml, cNode )
LOCAL nPosI, nPosF, cValue
nPosI := At( cXml, "<" + cNode + ">" ) + 2 + Len( cNode )
nPosF := At( cXml, "</" + cNode + ">" ) - 1
IF nPosI <= 0 .OR. nPosF <= 0 .OR. nPosF < nPosI
cValue := ""
ELSE
cValue := Substr( cXml, nPosI, nPosF - nPosI + 1 )
ENDIF
RETURN cValue

*This XmlNode() I create in post, not of my use, and without test.

Jos� M. C. Quintas

Em 03/07/2013 17:59, M., Ronaldo escreveu:
> Hi Jos� !
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Harbour Users" group.
> Unsubscribe: harbour-user...@googlegroups.com
> Web: http://groups.google.com/group/harbour-users
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Harbour Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to harbour-user...@googlegroups.com.

SD

unread,
Jul 4, 2013, 12:44:57 AM7/4/13
to harbou...@googlegroups.com
Thanks a lot José,  for this interesting fragment of code. So, this way we can convert the data from records of a dbf to xml... 

Ronaldo, thanks for your xml function. Whenever in future I get such requirement of converting to xml or reading from xml , will look into the examples of your and José.


On Thursday, 4 July 2013 01:56:24 UTC+5:30, José M. C. Quintas wrote:
I use functions for each block and XmlTag(), anything like this:

PROCEDURE Main
    LOCAL cXml

    USE filename
    cXml := [< filename id="] + Alias() + [">]
    XmlRecords( @cXml )
    cXml += [</filename>]
    ? cXml
    RETURN

STATIC FUNCTION XmlRecords( cXml )
    DO WHILE .NOT. Eof()
       cXml += XmlTag( "record", XmlFields() )
       SKIP
    ENDDO
    RETURN NIL

FUNCTION XmlFields( cXml )
    cXml += XmlTag( FieldName(1), FieldGet(1) )
    cXml += XmlTag( FieldName(2), FieldGet(2) )
    RETURN NIL

FUNCTION XmlTag( cNode, cValue )
    LOCAL cText
    cText := "<" + cNode + ">" + cValue + "</" + cNode + ">"
    RETURN cText

Jos� M. C. Quintas

M., Ronaldo

unread,
Jul 4, 2013, 12:31:37 PM7/4/13
to harbou...@googlegroups.com
// Another Sample

#include "hbmxml.ch"

STATIC s_mxml_error := .F.
STATIC s_mxml_error_msg := ""

// *---------------------------------------------------------------------------*
// F_XML_Read( cXML )
// Reading XML data
// *---------------------------------------------------------------------------*
FUNCTION F_XML_Read( cXML )

   LOCAL oXml
   LOCAL aNode := Array( 8 )
   LOCAL aData := Array( 64 )
   LOCAL bResult := .T.

   mxmlSetErrorCallback( @my_mxmlError() )

   oXml := mxmlLoadString( oXml, cXML, MXML_OPAQUE_CALLBACK )

   IF !( s_mxml_error )


      IF !( Empty( aNode[ 1 ] := mxmlFindElement( oXml, oXml, "Number", NIL, NIL, MXML_DESCEND ) ) )
         aData[ 1 ] := PadL( mxmlGetOpaque( aNode[ 1 ] ), 6, '0' )
      ENDIF

      IF !( Empty( aNode[ 1 ] := mxmlFindElement( oXml, oXml, "ID", NIL, NIL, MXML_DESCEND ) ) )
         aData[ 2 ] := mxmlGetOpaque( aNode[ 1 ] )
      ENDIF

      IF !( Empty( aNode[ 1 ] := mxmlFindElement( oXml, oXml, "Date", NIL, NIL, MXML_DESCEND ) ) )
         aData[ 3 ] := mxmlGetOpaque( aNode[ 1 ] )
      ENDIF

      IF !( Empty( aNode[ 1 ] := mxmlFindElement( oXml, oXml, "Invoice", NIL, NIL, MXML_DESCEND ) ) )
         aData[ 4 ] := mxmlGetOpaque( aNode[ 1 ] )
      ENDIF

      // *---------------------------------------------------------------------------*
      // "Messages"
      // *---------------------------------------------------------------------------*
      IF !( Empty( aNode[ 1 ] := mxmlFindElement( oXml, oXml, "Messages", NIL, NIL, MXML_DESCEND ) ) )

         IF !( Empty( aNode[ 2 ] := mxmlFindElement( aNode[ 1 ], aNode[ 1 ], "Code", NIL, NIL, MXML_DESCEND ) ) )
            aData[ 11 ] := mxmlGetOpaque( aNode[ 2 ] )
         ENDIF

         IF !( Empty( aNode[ 2 ] := mxmlFindElement( aNode[ 1 ], aNode[ 1 ], "Data", NIL, NIL, MXML_DESCEND ) ) )
            aData[ 12 ] := mxmlGetOpaque( aNode[ 2 ] )
         ENDIF
        
         // mxmlGetNextSibling can be use for a recursive loop

      ENDIF

      oXml := mxmlDelete( oXml )

   ELSE

      bResult := .F.

   ENDIF

   RETURN( bResult )

Paola Bruccoleri

unread,
Jul 4, 2013, 6:14:03 PM7/4/13
to harbou...@googlegroups.com
El 04/07/2013 13:31, M., Ronaldo escribió:
// Another Sample

#include "hbmxml.ch"

STATIC s_mxml_error := .F.
STATIC s_mxml_error_msg := ""

// *---------------------------------------------------------------------------*
// F_XML_Read( cXML )
// Reading XML data
// *---------------------------------------------------------------------------*
FUNCTION F_XML_Read( cXML )
  

Hi Ronaldo..
the function MY_MXMLERROR' is in the samples

now, the exe is created ok, BUT I get the same error that I had when testing the example of contributions

f:\harb\xml>prueba2

Error BASE/3012  Argument error: MXMLFINDELEMENT
Called from MXMLFINDELEMENT(0)
Called from F_XML_READ(30)
Called from MAIN(8)

Can I help me?
very thanks!

M., Ronaldo

unread,
Jul 4, 2013, 6:20:46 PM7/4/13
to harbou...@googlegroups.com
Ops: I forget this one

// *---------------------------------------------------------------------------*
// my_mxmlError( cErrorMsg )
// *---------------------------------------------------------------------------*
STATIC PROCEDURE my_mxmlError( cErrorMsg )

   s_mxml_error_msg := cErrorMsg
   s_mxml_error := .T.

   RETURN

M., Ronaldo

unread,
Jul 4, 2013, 6:28:12 PM7/4/13
to harbou...@googlegroups.com
Hi Paola !

Dont forget to include hbmxml.hbc in your .hbp project

hbmxml.hbc

Regards

# *****************************************
#.hbp sample file
# hbmk2 sample.hbp
/# *****************************************

# Program Name ( .exe )
-oTestXML

# Contrib
hbmxml.hbc

# Source files
SampleXML.PRG

Paola Bruccoleri

unread,
Jul 4, 2013, 7:55:20 PM7/4/13
to harbou...@googlegroups.com
Hi Ronaldo..
thank you for the idea, but is impossible!
I get the same error, the same as if I try with the example custom.prg of the contributions.

I have the harb version 3.2.0 of February 2013; Perhaps it is old
byeeeeeeeeee


DaNiEl MaXiMiLiAnO

unread,
Jul 2, 2013, 7:36:51 PM7/2/13
to harbou...@googlegroups.com
Hola Paola :
el ejemplo lo compilas con este batch.

@echo off
set backup=%path%
set path=%path;c:\hb32\bin
hbmk2 testmxml.prg
set path=%backup%
testmxml test.xml
pause

aqui compila perfecto con Windows 7 Home Premium 64, harbour nigthly (hb32)
harbour sources ( descargado en c:\harbour\core mediante GIT )

 
Saludos
                DaNIEl MaXiMiLiAnO


De: Paola Bruccoleri <pbruc...@adinet.com.uy>
Para: Lista Harbour-users <harbou...@googlegroups.com>
Enviado: martes, 2 de julio de 2013 20:20
Asunto: [harbour-users] Re: create XML
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-users+unsub...@googlegroups.com

Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-users+unsub...@googlegroups.com.

Paola Bruccoleri

unread,
Jul 5, 2013, 11:11:43 AM7/5/13
to harbou...@googlegroups.com
El 02/07/2013 20:36, DaNiEl MaXiMiLiAnO escribió:
Hola Paola :
el ejemplo lo compilas con este batch.

@echo off
set backup=%path%
set path=%path;c:\hb32\bin
hbmk2 testmxml.prg
set path=%backup%
testmxml test.xml
pause

aqui compila perfecto con Windows 7 Home Premium 64, harbour nigthly (hb32)
harbour sources ( descargado en c:\harbour\core mediante GIT )


Hola Daniel
si, ese ejemplo me compila ahora perfectamente; el problema está en el custom.prg y el otro, ya que da error la función findElement

en el ejemplo testmxml se usan estos argumentos:
hNode := mxmlFindElement( hTree, hTree, "choice",,, MXML_DESCEND )

pero en custom estos:
node := mxmlFindElement( tree, tree, "hash", NIL, NIL, MXML_DESCEND )

y el error es:

Error BASE/3012  Argument error: MXMLFINDELEMENT

evidentemente o está mal el ejemplo o se hicieron cambios al harbour posteriores al ejemplo, y ahora no corresponden los argumentos...
la verdad, no sé.!
Si tienes tiempo, puedes probar de crear el ejemplo custom y ejecutarlo a ver si te sale el mismo error?

muchas gracias
byeeeeeeeee

DaNiEl MaXiMiLiAnO

unread,
Jul 5, 2013, 1:12:53 PM7/5/13
to harbou...@googlegroups.com
Hola Paola, el ejemplo Custom.prg compila perfectamente.
genera un archivo XMl coneste contenido.

<?xml version="1.0" encoding="UTF-8"?>
-<group><hash checksum="f8f3971445b796ccba73454a0275c2f3" type="custom">FAELBVRvZGF5CxcyMDEzLTA3LTA1IDE0OjA0OjA3LjIzOQ==</hash></group>

adjunto imagen de la compilacion.

te recuerdo que descargue los fuentes de Harbour con Github. mi version de harbour nigthly es

C:\hb32\bin>harbour
Harbour 3.2.0dev (r1306132159)
Copyright (c) 1999-2013, http://harbour-project.org/

mi batch para compilar el ejemplo es

@echo off
set backup=%path%
set path=%path;c:\hb32\bin
hbmk2 custom.prg
set path=%backup%
custom.exe
pause


 
Saludos
                DaNIEl MaXiMiLiAnO


De: Paola Bruccoleri <pbruc...@adinet.com.uy>
Para: harbou...@googlegroups.com
Enviado: viernes, 5 de julio de 2013 12:11
Asunto: Re: [harbour-users] Re: create XML

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.

Web: http://groups.google.com/group/harbour-users
 
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
2013-07-05 14_06_52-tests.png

Juan Francolino

unread,
Jul 5, 2013, 2:53:07 PM7/5/13
to harbou...@googlegroups.com
Hi Paola,

Try with:

hbmk2 custom hbmxml.hbc


Regards


Juan

El 05/07/2013 12:11 p.m., Paola Bruccoleri escribi�:
> El 02/07/2013 20:36, DaNiEl MaXiMiLiAnO escribi�:
>> Hola Paola :
>> el ejemplo lo compilas con este batch.
>>
>> @echo off
>> set backup=%path%
>> set path=%path;c:\hb32\bin
>> hbmk2 testmxml.prg
>> set path=%backup%
>> testmxml test.xml
>> pause
>>
>> aqui compila perfecto con Windows 7 Home Premium 64, harbour nigthly
>> (hb32)
>> harbour sources ( descargado en c:\harbour\core mediante GIT )
>>
>>
> Hola Daniel
> si, ese ejemplo me compila ahora perfectamente; el problema est� en el
> custom.prg y el otro, ya que da error la funci�n findElement
>
> en el ejemplo testmxml se usan estos argumentos:
> hNode := mxmlFindElement( hTree, hTree, "choice",,, MXML_DESCEND )
>
> pero en custom estos:
> node := mxmlFindElement( tree, tree, "hash", NIL, NIL, MXML_DESCEND )
>
> y el error es:
> Error BASE/3012 Argument error: MXMLFINDELEMENT
>
> evidentemente o est� mal el ejemplo o se hicieron cambios al harbour
> posteriores al ejemplo, y ahora no corresponden los argumentos...
> la verdad, no s�.!
> Si tienes tiempo, puedes probar de crear el ejemplo custom y ejecutarlo
> a ver si te sale el mismo error?
>
> muchas gracias
> byeeeeeeeee
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Harbour Users" group.
> Unsubscribe: harbour-user...@googlegroups.com
> Web: http://groups.google.com/group/harbour-users
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Harbour Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to harbour-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages