XML: hate and love

704 views
Skip to first unread message

Francesco Perillo

unread,
Jul 20, 2017, 2:47:51 AM7/20/17
to harbou...@googlegroups.com

Somebody absolutely loves XML... Personally I hate XML.

Unfortunately I now need to read an XML file, extract data from it, elaborate it and the write the XML back with some other "tags"...

Anybody using XML that can give me some clues on which library to use?

Thanks
Francesco

Maurizio la Cecilia

unread,
Jul 20, 2017, 3:21:31 AM7/20/17
to Harbour User Group
Hi Francesco,
I currently use the mxml class present in xhb contrib. It's a lib developed by Lorenzo Fiorini and it works smootly for my needs, allowing reading, writing and searching xml files with a minimal learning curve.
I remember that Przemek saw mxml isn't the best choice and suggested the hbexpath lib, also present in contrib folder, but I never tried it as mxml is doing his job.
BR
--
Maurizio


--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-users+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

xamm-inf

unread,
Jul 20, 2017, 3:34:16 AM7/20/17
to Harbour Users

ZeTo Fernandes

unread,
Jul 20, 2017, 3:47:33 AM7/20/17
to Harbour Users
Hi, Francesco

I use to read and write xml files as plain text files.

ze

do...@people.net.au

unread,
Jul 20, 2017, 4:03:44 AM7/20/17
to harbou...@googlegroups.com
Hi

I use TXMLDocument class etc (see xHarbour documentation) which I understand has problems but for me it does everything that I need.

Firstly you need to decide if you want to build a logical tree from your XML data or process it on the fly.

Once you have a tree some information is effectively lost - for example:

<SPAN>this is a <BOLD>silly</BOLD> example</SPAN>

and

<SPAN><BOLD>silly</BOLD>this is an example</SPAN>

will both parse to the same tree but are clearly different.

If you have situations like this you probably need to parse on the fly.

However if it is more a straight data application with all data in terminal nodes and non-terminal nodes carrying no data (but can have properties) then building a logical tree is probably easiest (given sufficient memory).

Regards
Doug




Lorenzo Fiorini

unread,
Jul 20, 2017, 4:14:35 PM7/20/17
to harbou...@googlegroups.com


> On 20 Jul 2017, at 09:21, Maurizio la Cecilia <m.lac...@gmail.com> wrote:
>
> Hi Francesco,
> I currently use the mxml class present in xhb contrib. It's a lib developed by Lorenzo Fiorini and it works smootly for my needs, allowing reading, writing and searching xml files with a minimal learning curve.

That code was originally written by Giancarlo Niccolai. I simply helped Przemyslaw to port it from xHarbour to Harbour.

best regards,
Lorenzo

Clippero

unread,
Jul 21, 2017, 7:43:58 AM7/21/17
to Harbour Users
tohash the best !

With:

FT_FOPEN()
FT_FSELECT()
FT_READLINE()
FT_FGOTOP()
FT_FLASTRE()
FT_FCLOSE
Etc....

Open and work with .txt file

Maurizio la Cecilia

unread,
Jul 22, 2017, 1:00:43 PM7/22/17
to harbou...@googlegroups.com

Ok, sorry: "Give Lorenzo what is of Lorenzo and Giancarlo what is of Giancarlo"...
Thanks Lorenzo for your suggestion and both for the xml contrib.
Best regards.
--
Maurizio

Klas Engwall

unread,
Jul 22, 2017, 5:44:49 PM7/22/17
to harbou...@googlegroups.com
Hi Francesco, Maurizio & others
There is also the Mini-XML library by Michael Sweet with Harbour
wrappers, fixes and some test code by Petr Chornyj and others. It is
included in Harbour as contrib\hbmxml. Michael Sweet has a complete
manual at https://michaelrsweet.github.io/mxml/mxml.html

I use that lib as a cornerstone of my xlsx lib with no problems at all.

Regards,
Klas

M., Ronaldo

unread,
Jul 25, 2017, 1:34:41 PM7/25/17
to Harbour Users
#include "hbmxml.ch"
Procedute Sample_Xml( cFile )
   LOCAL hNode := { => }
   LOCAL oXml  := mxmlNewXML("1.0")
   hNode[ 1 ] := mxmlNewElement( oXml, "TGroup" )
   mxmlElementSetAttr( hNode[ 1 ], "version", "1.00" )
   mxmlElementSetAttr( hNode[ 1 ], "xmlns", "http://www.any.url.com" )
   hNode[ 2 ] := mxmlNewElement( hNode[ 1 ], "bill" )
   hNode[ 3 ] := mxmlNewElement( hNode[ 2 ], 'TData' )
   hNode[ 4 ] := mxmlNewElement( hNode[ 3 ], "code" )
   mxmlNewText( hNode[ 4 ], 0, "01" )
   hNode[ 4 ] := mxmlNewElement( hNode[ 3 ], "data" )
   mxmlNewText( hNode[ 4 ], 0, "Sample" )
   hNode[ 3 ] := mxmlNewElement( hNode[ 2 ], 'TDate' )
   hNode[ 4 ] := mxmlNewElement( hNode[ 3 ], "date" )
   mxmlNewText( hNode[ 4 ], 0, STOD( Date*( ) )
   mxmlSaveFile( oXml, LOWER( cFile ), @whitespace_cb() )
   RETURN

M., Ronaldo

unread,
Jul 25, 2017, 1:48:45 PM7/25/17
to Harbour Users
Procedure Sample_XML_Read( cXML )
   LOCAL hXml := { => }
   LOCAL oXml

   mxmlSetErrorCallback( @my_mxmlError() )

   oXml := mxmlLoadString( oXml, cXML, MXML_OPAQUE_CALLBACK )

   IF !( s_mxml_error )

      IF !( Empty( hXml[ 1 ] := mxmlFindElement( oXml, oXml, "TGroup", NIL, NIL, MXML_DESCEND ) ) )
         IF !( Empty( hXml[ 2 ] := mxmlFindElement( hXml[ 1 ], hXml[ 1 ], "bill", NIL, NIL, MXML_DESCEND ) ) )
            IF !( Empty( hXml[ 3 ] := mxmlFindElement( hXml[ 2 ], hXml[ 2 ], "TData", NIL, NIL, MXML_DESCEND ) ) )
               IF !( Empty( hXml[ 4 ] := mxmlFindElement( hXml[ 3 ], hXml[ 3 ], "code", NIL, NIL, MXML_DESCEND ) ) )
                  hXml['code'] := hXml[ 4 ]
               ENDIF
               IF !( Empty( hXml[ 4 ] := mxmlFindElement( hXml[ 3 ], hXml[ 3 ], "data", NIL, NIL, MXML_DESCEND ) ) )
                  hXml['data'] := hXml[ 4 ]
               ENDIF
            ENDIF
            IF !( Empty( hXml[ 3 ] := mxmlFindElement( hXml[ 2 ], hXml[ 2 ], "TDate", NIL, NIL, MXML_DESCEND ) ) )
               IF !( Empty( hXml[ 4 ] := mxmlFindElement( hXml[ 3 ], hXml[ 3 ], "date", NIL, NIL, MXML_DESCEND ) ) )
                  hXml['date'] := hXml[ 4 ]
               ENDIF
            ENDIF
         ENDIF
      ENDIF

      oXml := mxmlDelete( oXml )
     
      ? hXml['code'], hXml['data'], hXml['date']

RETURN

STATIC PROCEDURE my_mxmlError( cErrorMsg )

   s_mxml_error_msg := cErrorMsg
   s_mxml_error := .T.

RETURN

Nenad Batoćanin

unread,
Jul 25, 2017, 9:24:11 PM7/25/17
to Harbour Users
Can you specify some simple example for reading / writing a XML file?

NB

M., Ronaldo

unread,
Jul 26, 2017, 12:27:13 AM7/26/17
to Harbour Users
Attached
Tested and Working :-)
XML.PRG

Nenad Batoćanin

unread,
Jul 26, 2017, 10:38:51 AM7/26/17
to Harbour Users
Thank you Ronaldo and Jose :)

I use my simple system that I made years ago. The problem with this system is that sometimes it's too slow, but it's too big a job to speed up, so I wanted to use it as a wrapper to mxml or some other system. For example, I create XML with this code:

oXml := XML_Doc ()

oXml:Add ("Root")
oXml:Add (" Machine")
oXml:Add ("  Item")
oXml:Add ("   Brand", "XYZ")
oXml:Add ("   Code", "001")

oXml:Write ("test.xml")

I use leading spaces as level indicator. Reading and parsing XML files:

oXml := XML_Doc ()
oXml:Parse ("test.xml")
oXml:GetNode ("Brand")  // "XYZ"
...

Regards, NB

Nenad Batoćanin

unread,
Jul 29, 2017, 8:50:22 PM7/29/17
to Harbour Users
I have two maybe stupid questions:

- Is there a way to get XML structured, not in one line? For example:

<group>
   <note>
      <to>Tove</to>
       <from>Jani</from>

Not:

<group><note><to>Tove</to><from>Jani</from>


- Where can I find the some manual for mxml functions?

Thank you, NB

Maurizio la Cecilia

unread,
Jul 30, 2017, 2:00:50 AM7/30/17
to Harbour User Group
Hi Nenad,
please try this:
oDoc:Write(  fname, HBXML_STYLE_INDENT + HBXML_STYLE_TAB )
oDoc:Read( fname, HBXML_STYLE_INDENT + HBXML_STYLE_TAB )

best regards.
Maurizio

--

Maurizio la Cecilia

unread,
Jul 30, 2017, 2:54:00 AM7/30/17
to Harbour User Group
Hi Nenad,

Best regards.
Maurizio

Il 30 lug 2017 2:50 AM, "Nenad Batoćanin" <nbato...@wings.rs> ha scritto:
--

Nenad Batocanin

unread,
Jul 30, 2017, 9:52:50 PM7/30/17
to harbou...@googlegroups.com

Sorry I do not understand? How do I create a oDoc class? I use procedure mxmlSaveFile for saving XML.

 

Regards, NB


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.


For more options, visit https://groups.google.com/d/optout.

--

--
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.

Nenad Batocanin

unread,
Jul 30, 2017, 9:52:50 PM7/30/17
to harbou...@googlegroups.com

Thank you, but this instruction seems pretty complicated to me :(  I wanted to see arguments for basic functions, such as mxmlSaveFile.

 

Regards, NB

 

From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] On Behalf Of Maurizio la Cecilia
Sent: Sunday, July 30, 2017 8:54 AM
To: Harbour User Group <harbou...@googlegroups.com>
Subject: Re: [harbour-users] Re: XML: hate and love

 

Hi Nenad,


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.


For more options, visit https://groups.google.com/d/optout.

--

--
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.

Maurizio la Cecilia

unread,
Jul 31, 2017, 3:22:56 AM7/31/17
to Harbour User Group
Hi Nenad,
the suggestion I sent you is related to hbxml wrapper to mxml present in the xhb contrib folder.
Using the hbxml samples and the link to the mxml doc (I sent you in a separate post) you should succeed in building a working code.
Let me know if you need some further hint. 
Best regards.
Maurizio


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+unsubscribe@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
--
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-users+unsubscribe@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
--
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-users+unsubscribe@googlegroups.com.

Guillermo Varona Silupú

unread,
Jul 31, 2017, 7:34:40 AM7/31/17
to harbou...@googlegroups.com

Hi Nenad:

This wrapper is related to this utility:

http://michaelrsweet.github.io/mxml/

Doc.: http://michaelrsweet.github.io/mxml/mxml.html

http://michaelrsweet.github.io/mxml/mxml.html#mxmlSaveFile

I hope this clarifies the matter.

BestRegards

GVS

Nenad Batocanin

unread,
Jul 31, 2017, 9:44:35 PM7/31/17
to harbou...@googlegroups.com

Thank you very much! That's what I'm looking for.

 

Regards, NB

 

From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] On Behalf Of Guillermo Varona Silupú
Sent: Monday, July 31, 2017 1:35 PM
To: harbou...@googlegroups.com
Subject: Re: [harbour-users] Re: XML: hate and love

 

Hi Nenad:

--

Nenad Batoćanin

unread,
Aug 4, 2017, 9:04:20 PM8/4/17
to Harbour Users
Ok, i tried:

- MiniXML. It is ok, but I dont like procedural approach and "callback" functions. Also, I did not find a way to automatically create "formatted" XML. 

- I try expat, but I did not understand how it worked. There is no documentation, so I gave up.

- TXML class - this is great, there's everything I need! Very simple and transparent use.

regards, NB


Guillermo Varona Silupú

unread,
Aug 5, 2017, 10:13:48 AM8/5/17
to harbou...@googlegroups.com

Hi Nenad:

Mini-XML seems quite complete, however it is very hard to learn.


El 04/08/2017 a las 08:04 p.m., Nenad Batoćanin escribió:
Ok, i tried:

- MiniXML. It is ok, but I dont like procedural approach and "callback" functions. Also, I did not find a way to automatically create "formatted" XML.

Reply all
Reply to author
Forward
0 new messages