xHb xml GetContext: read a file from the beginning

616 views
Skip to first unread message

Luigi Ferraris

unread,
Jul 31, 2012, 6:03:59 AM7/31/12
to harbou...@googlegroups.com
Hi to everybody.
I'm trying to understand Txml usage. In this moment I want to scan a xml from the beginning to the ending.
I'm using Harbour Windows Binaries Nightly versione ChangeLog 17904 2012-07-23 20:54:33Z

I do some experiments and someone works fine but I tried this code:

   IF ! hb_fileExists( cFileName )
      RETURN
   ENDIF

   cString := MEMOREAD( cFileName )

   oDoc := TXmlDocument():GetContext()

   oDoc:Read( cString, HBXML_STYLE_NOESCAPE )

   IF oDoc:nError != HBXML_ERROR_NONE
      MsgStop( "xml file parsing error " + STR( oDoc:nError ) )
      RETURN
   ENDIF

But related with line "oDoc := TXmlDocument():GetContext()" I receive this RTE (I'm using HbQt):

"HBQT Runtime Error, Error Base/1004 No exported method: GETNODE Called from TXmlDocument():GetContext(0)"

My code is wrong?

Many thanks in advance for any help

Luigi

Massimo Belgrano

unread,
Jul 31, 2012, 6:33:06 AM7/31/12
to harbou...@googlegroups.com
you re using xhb (a very "bad" library but compatible with xharbour)
his sample is  contrib\xhb\tests\xml1.prg 
i suggest hbmxml.lib so read contrib\hbmxml\tests

this is part of source
   oDoc := TXmlDocument():New( cString, HBXML_STYLE_NOESCAPE )
   IF oDoc:nError != HBXML_ERROR_NONE
      WAIT "xml file parsing error " + Str( oDoc:nError )
      RETURN
   ENDIF
   oBook := oDoc:findfirst( "book" )

2012/7/31 Luigi Ferraris <luigfe...@gmail.com>



--
Massimo Belgrano

luigi-gmail

unread,
Jul 31, 2012, 8:01:13 AM7/31/12
to harbou...@googlegroups.com
Hi Massimo, many thanks for your quickly replay. I will read about hbmxml.lib

Anyway related with:
you re using xhb (a very "bad" library but compatible with xharbour)
Sometimes a programmer must also think about the weight of the final program and then make choices, otherwise he would include all the libraries to prevent any eventuality or need or better performance. The library "XHB" includes some useful features and then, without prejudice to the previous point, add another library would unnecessarily swell the final program. Probably, hbmxml.lib is a better solution I don't know at this moment.

Very personal point of view (
not strictly related to the subject): only those functions that are the heart of Harbour should be prefixed with "hb_" while all the functions of the contrib libraries should have their prefix, I mean, for example, hb_qwith is a "XHB" function but seems to be part of Harbour at the same time hb_crypt and so on.
his sample is  contrib\xhb\tests\xml1.prg
this is part of source
   oDoc := TXmlDocument():New( cString, HBXML_STYLE_NOESCAPE )
   IF oDoc:nError != HBXML_ERROR_NONE
      WAIT "xml file parsing error " + Str( oDoc:nError )
      RETURN
   ENDIF
   oBook := oDoc:findfirst( "book" )

I read and understand but I have another problem: how can I read a xml file from the beginning to the ending (add: without knowing a starting tag)?

My case: I want use xml file to store application properties or configuration but not every properties can be customized.
Yes, I know I can write xml like this
<config>
    <tagSection1>
        <tag1>value</tag1>
        ......
        <tagN>value</tagN>
    </tagSection1>
............

</config>

and for this reason I can use oBook := oDoc:findfirst( "config" ) and then use iterator.... but can I omit <config> and start from the first (unknown) tag name? In other words like
DO WHILE NOT EOF()
    readnext
ENDDO

One time I can code xml in this way
<tagSection1>
    <tag1>value</tag1>
        ......
    <tagN>value</tagN>
</tagSection1>

Again I can code xml in this way
<tagSection2>
    <tag1>value</tag1>
        ......
    <tagN>value</tagN>
</tagSection2>

Yes I can start everytime with <config> and this will be my solution.

Many thanks for your suggestion and answer: I will try.

Cheers


Viktor Szakáts

unread,
Jul 31, 2012, 8:22:06 AM7/31/12
to harbou...@googlegroups.com
> Sometimes a programmer must also think about the weight of the final program
> and then make choices, otherwise he would include all the libraries to
> prevent any eventuality or need or better performance. The library "XHB"
> includes some useful features and then, without prejudice to the previous
> point, add another library would unnecessarily swell the final program.
> Probably, hbmxml.lib is a better solution I don't know at this moment.

Or hbexpat. Both have much superior xml implementations
than xhb lib. If you have any choice, drop xhb lib and replace
it with tier-1, non-compatibility libs. xhb is a compatibility lib
which doesn't hold the quality/design constraints of Harbour,
in fact these functions are kept separately exactly because
of that.

> Very personal point of view (not strictly related to the subject): only
> those functions that are the heart of Harbour should be prefixed with "hb_"
> while all the functions of the contrib libraries should have their prefix, I
> mean, for example, hb_qwith is a "XHB" function but seems to be part of
> Harbour at the same time hb_crypt and so on.

There is no such rule that only core functions may get
the HB_ prefix. There are certain situations when HB_
is valid in contribs, f.e. for non 1-to-1 wrappers in a
wrapper lib, or extensions in a compatibility lib, or the
wrapped API doesn't have namespace. But, it should
be rather the exception than the rule.

You can also find examples where HB_ prefix is wrongly
used, but we have to keep it for compatibility:
XHB, HBMISC, HBZIPARC.

> I read and understand but I have another problem: how can I read a xml file
> from the beginning to the ending (add: without knowing a starting tag)?

I recommend the user's mailing list for this topic.

-- Viktor

luigi-gmail

unread,
Jul 31, 2012, 8:41:05 AM7/31/12
to harbou...@googlegroups.com
Hi Viktor
> Or hbexpat. Both have much superior xml implementations
> than xhb lib. If you have any choice, drop xhb lib and replace
> it with tier-1, non-compatibility libs. xhb is a compatibility lib
> which doesn't hold the quality/design constraints of Harbour,
> in fact these functions are kept separately exactly because
> of that.
Ok I will read and try.
> You can also find examples where HB_ prefix is wrongly
> used, but we have to keep it for compatibility:
> XHB, HBMISC, HBZIPARC.
Yes, I know. The problem is: I think this is a Harbour function but I
can't compile program... because I don't add relate contrib....then I
must investigate who is the owner. Anyway, this must be the knowledge of
Harbour users :-))

> I recommend the user's mailing list for this topic.
Ok.

Many thanks

Viktor Szakáts

unread,
Jul 31, 2012, 8:56:37 AM7/31/12
to harbou...@googlegroups.com
> Yes, I know. The problem is: I think this is a Harbour function but I can't
> compile program... because I don't add relate contrib....then I must
> investigate who is the owner. Anyway, this must be the knowledge of Harbour
> users :-))

It's generic problem, unrelated to HB_ prefix.
A simple 'grep -R' in Harbour root will always
give an answer. For wrongly named HB_ prefixed
functions, the best is to avoid them.

-- Viktor

Massimo Belgrano

unread,
Jul 31, 2012, 9:46:05 AM7/31/12
to harbou...@googlegroups.com
here you can find the complete harbour func and wich is library



2012/7/31 luigi-gmail <luigfe...@gmail.com>

Yes, I know. The problem is: I think this is a Harbour function but I can't compile program... because I don't add relate contrib....then I must investigate who is the owner. Anyway, this must be the knowledge of Harbour users :-))




--
Massimo Belgrano


luigi-gmail

unread,
Jul 31, 2012, 2:54:25 PM7/31/12
to harbou...@googlegroups.com
Il 31/07/2012 15.46, Massimo Belgrano ha scritto:
> here you can find the complete harbour func and wich is library
>
> http://www.elektrosoft.it/tutorials/Harbour-Reference-Guide/harbour-complete-functions-list.htm
>
>
> --
> Massimo Belgrano
>
>
Hi Massimo, many thanks for this link: very useful!

Cheers

Luigi Ferraris

luigi-gmail

unread,
Jul 31, 2012, 2:56:22 PM7/31/12
to harbou...@googlegroups.com
Il 31/07/2012 14.56, Viktor Szakáts ha scritto:
> It's generic problem, unrelated to HB_ prefix. A simple 'grep -R' in
> Harbour root will always give an answer. For wrongly named HB_
> prefixed functions, the best is to avoid them. -- Viktor
Many thanks for suggestion!

Cheers

Luigi Ferraris
Reply all
Reply to author
Forward
0 new messages