April 30, 2024, 09:36:43 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


XML Parser

Started by LarryMc, March 31, 2007, 12:00:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dogge

Hi Larry,

I'm trying to use your CXmlLM functions for storing settings for my programs. My goal is to be able to modify settings with any texteditor or an XML editor like XML Marker and the reload the file in my program.
I can load the settings once but subsequent loads fail, with either "Current Node has no children" or a program termination, depending on if I comment out the FreeNodeMem call or not.

Here is my code

$use "CXmlLM.lib"
$include "windows.inc"
$include "CXmlLM.inc"

CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
CONST LISTBOX_3 = 3
DIALOG d1

def MyParams as CXmlLM
string MyParamsFileName : MyParamsFileName=GetStartPath+"MyParams.xml"
int Delay1: Delay1=5000
int Delay2: Delay2=2000
int Delay3: Delay3=4000

CREATEDIALOG d1,0,0,270,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@SYSBUTTON,"Load the XML file",15,20,235,26,0x50000000,BUTTON_1
CONTROL d1,@SYSBUTTON,"Edit XML file with external editor",15,140,235,26,0x50000000,BUTTON_2
CONTROL d1,@LISTBOX,"ListBox1",15,50,235,85,0x50800140,LISTBOX_3

domodal d1

end

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
LoadMyParams()
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
system "notepad.exe", getstartpath+"MyParams.xml"
ENDIF
CASE LISTBOX_3
/* respond to control notifications here */
ENDSELECT
ENDSELECT
RETURN
ENDSUB

sub LoadMyParams()
string _param
while (getstringcount(d1,LISTBOX_3)>0) : deletestring d1, LISTBOX_3, 0 : endwhile
if MyParams.FileLoad(MyParamsFileName)
MyParams.ErrMsg()
else
if MyParams.FindRoot()
MyParams.ErrMsg()
else
if MyParams.FindFirstChild("Delay1")=0
MyParams.GetDat(_param, Delay1) : Delay1=val(_param)
MyParams.FindParent()
addstring d1, LISTBOX_3, "Delay1"+str$(Delay1)
else
MyParams.ErrMsg()
endif
if MyParams.FindFirstChild("Delay2")=0
MyParams.GetDat(_param, Delay2) : Delay2=val(_param)
MyParams.FindParent()
addstring d1, LISTBOX_3, "Delay2"+str$(Delay2)
else
MyParams.ErrMsg()
endif
if MyParams.FindFirstChild("Delay3")=0
MyParams.GetDat(_param, Delay3) : Delay3=val(_param)
MyParams.FindParent()
addstring d1, LISTBOX_3, "Delay3"+str$(Delay3)
else
MyParams.ErrMsg()
endif
endif
MyParams.FreeNodeMem()
endif

endsub


and my test data

<?xml version="1.0"?>
<XMLtest>
        <Delay1>5055</Delay1>
        <Delay2>2002</Delay2>
        <Delay3>4004</Delay3>
</XMLtest>

I appreciate your efforts with the library which I have found to be very useful for generating log-files in my program.

Should I be able to use the library the way I'm doing with loading and reloading the data?

Thanks
/Douglas

LarryMc

Douglas,
You're having the same problem I'm having with an application I'm working on.
The thing that are in common between our 2 programs are that we're both declaring our CXmlLM typr variable at a global level then calling the methods inside a dialog.

I've sent Paul a copy of my xml library source code to see if he can figure out why it is acting weird with the dialog.

In the mean time I'm going to try a couple of other ideas to see if there is a way to get it to work.

Sorry for the problem.  If you can, work on another part of your program while I try to figure out what's going on.

Don't give up on me yet.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Douglas,
This works.
I don't know if this is "THE" fix or just a work around.  I'll have to wait till I hear something from Paul.

Instead of MyParams being global it is now local to the subroutine; it is created dynamically and when the subroutine returns the system takes care of closing the instance of CXmlLM.

$use "CXmlLM.lib"
$include "windows.inc"
$include "CXmlLM.inc"

CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
CONST LISTBOX_3 = 3
DIALOG d1

'def MyParams as CXmlLM
string MyParamsFileName : MyParamsFileName=GetStartPath+"MyParams.xml"
int Delay1: Delay1=5000
int Delay2: Delay2=2000
int Delay3: Delay3=4000

CREATEDIALOG d1,0,0,270,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@SYSBUTTON,"Load the XML file",15,20,235,26,0x50000000,BUTTON_1
CONTROL d1,@SYSBUTTON,"Edit XML file with external editor",15,140,235,26,0x50000000,BUTTON_2
CONTROL d1,@LISTBOX,"ListBox1",15,50,235,85,0x50800140,LISTBOX_3

domodal d1

end

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
LoadMyParams()
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
system "notepad.exe", getstartpath+"MyParams.xml"
ENDIF
CASE LISTBOX_3
/* respond to control notifications here */
ENDSELECT
ENDSELECT
RETURN
ENDSUB

sub LoadMyParams()
POINTER MyParams
SETTYPE MyParams,CXmlLM
MyParams = NEW(CXmlLM,1)
string _param
while (getstringcount(d1,LISTBOX_3)>0) : deletestring d1, LISTBOX_3, 0 : endwhile
if #MyParams.FileLoad(MyParamsFileName)
#MyParams.ErrMsg()
else
if #MyParams.FindRoot()
#MyParams.ErrMsg()
else
if #MyParams.FindFirstChild("Delay1")=0
#MyParams.GetDat(_param, Delay1) : Delay1=val(_param)
#MyParams.FindParent()
addstring d1, LISTBOX_3, "Delay1"+str$(Delay1)
else
#MyParams.ErrMsg()
endif
if #MyParams.FindFirstChild("Delay2")=0
#MyParams.GetDat(_param, Delay2) : Delay2=val(_param)
#MyParams.FindParent()
addstring d1, LISTBOX_3, "Delay2"+str$(Delay2)
else
#MyParams.ErrMsg()
endif
if #MyParams.FindFirstChild("Delay3")=0
#MyParams.GetDat(_param, Delay3) : Delay3=val(_param)
#MyParams.FindParent()
addstring d1, LISTBOX_3, "Delay3"+str$(Delay3)
else
#MyParams.ErrMsg()
endif
endif
'

endif
#MyParams.FreeNodeMem()
endsub
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Dogge

Hi Larry,

thanks for the workaround, it is perfectly useful for loading and reloading settings, however when I use it for logging purposes I need it to be global as I add to the log from several different routines in the program. In the logging case I never load a file from disk, I just do a FileSave and a FileNew when one log should be closed and another opened, and this works fine. I had to comment out the FreeNodeMem after the FileSave, otherwise the FileNew terminated the program.

I wont give up, I like the functionality and I think it is easy to work with.

/Douglas


LarryMc

Found flaw that was causing problem for Douglas and myself.

Posted revised CXmlLB class library with help file and examples at
http://www.ionicwind.com/forums/index.php/topic,1603.msg15670.html#msg15670

[Douglas]
Your original program as you posted here works just fine now.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Dogge

Great, I tried it and it worked  ;D ;D with one exception :o. When I kept the FreeNodeMem call the program dumped on me when I closed the window.
I was thinking that maybe its not necessary to have it in the code, but it would be good to know if I should have that call there or should it not be there?

/Douglas



LarryMc

I've been running some test to see if there are memory leaks by leaving the FreeNodeMem out.

so far I haven't seen any.

So like the DR. says "If it hurts when you do that, then don't do that" ;)

I'll keep you posted if I find anything new.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Dogge

I'll leave it out for now, as it don't seem to cause any problems. Can you reproduce the error I have with the code I posted?
/Douglas

LarryMc

Not with your code but I'm pursuing issues with my application which can also have an impact on yours.
I'll let you know ASAP.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Fixed bugs that caused crashes.
Update version at:
http://www.ionicwind.com/forums/index.php/topic,1603.msg15670.html#msg15670

[Douglas]
Put the FreeNodeMem() calls back in your program like the examples show.
Failure to do so will cause memory leaks.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Dogge

Great job Larry ;D
downloaded, tested and it works as expected.

I'm very pleased with the functionality, and I'll let you know if I find any problem or have some ideas for new and added functionality.

Thanks again!

/Douglas



LarryMc

Quote from: Dogge on July 13, 2007, 09:30:49 AM
and I'll let you know if I find any problem
As an ex-teacher turned chemical engineer once said at one of our Engineering Department meetings with Plant Operations,

"How do you expect me to ever finish my project if you keep finding things wrong."

:o :D
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Dogge

Quote from: Larry McCaughn on July 13, 2007, 11:04:03 AM
"How do you expect me to ever finish my project if you keep finding things wrong."
:o :D
lol, the last bug will never ::) be found.

Dogge

Hi Larry,
I ran into some more problems. I'm attaching 4 different programs to describe the problem. The background for my issues is that I wanted to use your lib to create log-files and in one program I need to load the logfile and continue adding to it. These programs (in zip file) illustrate my problem:
XMLtest2.eba; works
XMLtest3.eba; same as "2" except line 50 where I added a numeric character to the tag name, get the error "Node Name contains illegal characters"
XMLtest4.eba; dumps, the difference here is that I'm adding my new node directly as a child node to the root node, whereas in "2" and "3" I did a find child node and added the node as a peernode
XMLtest5.eba; same as "4" but with an additional numeric character in the tag name and I get the same error as in test "2".

XML file for test is the same as previous

I'll appreciate if you could check if I'm doing something wrong or if I found some more bugs.

Thanks
/Douglas

REDEBOLT

Quote from: Dogge on July 13, 2007, 12:32:00 PM
Quote from: Larry McCaughn on July 13, 2007, 11:04:03 AM
"How do you expect me to ever finish my project if you keep finding things wrong."
:o :D
lol, the last bug will never ::) be found.

Each bug found increases the probability that one more bug will be found.
Regards,
Bob

Rock Ridge Farm (Larry)

There not bugs - They are undocumented features. :)

LarryMc

July 18, 2007, 12:08:23 PM #41 Last Edit: July 18, 2007, 12:10:57 PM by Larry McCaughn
Don't BUG me!

Today's my birthday!

Douglas,

I've got to take some limbs to the dump.
In a couple of hours I will look into your "discoveries"

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Dogge

Congratulations!  ;D

No need to spend your birthday looking at my code, I have plenty of other things to work on.

/Douglas

LarryMc

New ver of CXmlLM posted at http://www.ionicwind.com/forums/index.php/topic,1603.msg15670.html#msg15670

Douglas
Fixed your problems:
   Crash when adding Child off root node (due to structure change in last update)
   error when adding 0-9 to a tag name(due to operator precedence error)

Let me know if you find any more "undocumented training aids". ;)

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Seems I took 2 problems out and put a new one in. ::)

A newer version will be forthcoming.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

CXmlLM V2.04 posted at http://www.ionicwind.com/forums/index.php/topic,1603.msg15670.html#msg15670

Fixed problem in FileNew method that would cause crash when trying to add childnodes.
(Root node end-tag creation had not been changed to support other revisions made in V2.03)

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Dogge

Great work, thanks, I'll try it as soon as I can and let you know if I find anything else.
/Douglas

Dogge

Hi, it's me again  :)

When I tested my first program where I used CXmlLM with the new 2.04 version it dumped on me  :(.
I backed down  to 1.0 where it works.
Tested 2.0 - 2.03, none works, 2.04 lets me run my program a bit longer but then it dies with a memory error.
I have traced the problem to an AddChildNode call, same type of call is used earlier in the program with the same type of arguments.
As the same call works earlier in the program I haven't done a test program to reproduce the error.

I'm sorry to bug you and I'll appreciate if you could take a look at the problem when you have time, I'll stick to 1.0 for now.

/Douglas


LarryMc

Douglas

For me to see what's wrong I need to see your code.

My problem is that all my examples work fine; all YOUR examples with "myparams.xml" work fine.

I can't fix it unless I can see it broke.

Now, the a big difference between version 1 and the later versions is that ver 1 was limited to string values.

The newer versions use istring$ so it will handle string$ up to 100k on data.

You having to go back to version 1 at this time tells me there is something wrong with a string somewhere.

But like I said I don't know how to fix it unless I see it.

Sorry,

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Dogge

I understand that you need to see the code, I have been working with software support and it's a nightmare with trying to chase bugs without seeing what people do. The code is part of a larger back-end package and I'll see what I can put together for you as a test case. It will take me a while so I'll stick with version 1 for the next couple of days.

/Douglas