The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 load XML-file into Tree object
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

TreeNode

64 Posts

Posted - 10/29/2009 :  1:36:42 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Version: Origin 8
Operating System: Windows XP

Hello everbody!
I am new to this, and have allready many questions.
Here is one of them:

I want to import data from XML-file to origin,
using a function from the Tree class:

syntax:
BOOL Load( LPCSTR File, int nType = 0 )


a code example shows:


void Tree_Load_ex1()
{
    Tree myTree;
    myTree.Load("xyz.xml", 0);            
}


I got a bit confused when trying the following:


void test_load_xml() {
    Tree myTree;
    if( myTree.Load("c:\pojects\data\myData.xml") ) {
        out_tree(myTree);
    }
    else {
        out_str("File could not be load!");
    }
}


In some cases it works, in some not. But I dont understand for what reasons.
For example I saved the file myData.xml in an other path: c:\myData
and tried it with
myTree.Load("c:\Data.xml")

and it didnt work.

Another wirred example is, I had two XML-files. They had the same content, but different names, but in the same path.
One of them could be load, the other file not. confused?? me too!!

I got more confusing things: I put the file in a folder called XML.
So the path was: c:\projects\data\XML\myData.xml
Now I got a Runtime Error:


Runtime Error!

Program: C:\Programme\OriginLab\Origin8\Origin8.exe


abnormal program termination


But when I use a Labtalk-script to get path and filename like this:


getfile *.xml
filename$ = %A;
filepath$ = %B


and then call OriginC-function:


void test_load_xml(string filename, string filepath) {
    Tree myTree;
    if( myTree.Load(filepath + filename) ) {
        out_tree(myTree);
    }
    else {
        out_str("File could not be load!");
    }
}


like this, in Labtalk-script:

test_load_xml(filename$, filepath$)


Everything works fine. But I feel a bit nervous about these errors
which occured by using this function. Because I dont know why and when they occur.

Did anybody make experiences with that? Then tell me please.
Thank you!

greetz

<!-- helping each other
is a good thing..
..like TreeNode holding
the leaves of a Tree -->

Iris_Bai

China
Posts

Posted - 10/30/2009 :  06:11:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please take a look below codes
quote:
In some cases it works, in some not. But I dont understand for what reasons.
For example I saved the file myData.xml in an other path: c:\myData
and tried it with

myTree.Load("c:\Data.xml")


1. There is a typo, your file name is myData.xml, but in coding, the file path is c:\Data.xml.
You can use BOOK string::IsFile() to check if file is existed.
2. And there is another mistake, should use \\ as separator in path string, not \.
3. Missed ; in the end of codes.

So the correct code should be:
myTree.Load("C:\\myData.xml");

Iris
Go to Top of Page

TreeNode

64 Posts

Posted - 10/30/2009 :  10:48:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Iris!
Thanks for your reply, and finding my mistakes!

quote:
1. There is a typo, your file name is myData.xml, but in coding, the file path is c:\Data.xml.
You can use BOOK string::IsFile() to check if file is existed.


This typo only occured by posting my question. When testing code I checked very often, if a pasted in the korrekt filename.
But to check if file exists with: BOOL string.IsFile() is a good idea!
Thanks for that!

quote:
3. Missed ; in the end of codes.


This is a typo too, which only happend when I posted this. In code I sometimes forget it too. But when testing my code, compiling and linking was done. Or compiler returns error, and I fixed it.

quote:
2. And there is another mistake, should use \\ as separator in path string, not \.


This is a really good idea, thanks a lot for that. When I replace the single slash \ with a double slash \\ everything works fine. Like in this example:

void Tree_Load_ex1() {
    Tree myTree;
    if ( myTree.Load("C:\\data\\test\\exam\\test.xml") ) {
    	out_tree(myTree);
    }
    else {
    	out_str("Could not load file!");
    }
}


But what would yu say about that... Here are some examples that work:

myTree.Load("C:\\data\\test\\exam\\test.xml")

myTree.Load("C:\data\\test\\exam\\test.xml")

myTree.Load("C:\\data\\test\exam\\test.xml")

myTree.Load("C:\data\\test\exam\\test.xml")

myTree.Load("C:\\\data\\test\\exam\\test.xml")

myTree.Load("C:\\\\data\\test\\exam\\test.xml")

myTree.Load("C:\\test.xml")


And here are some examples that doesnt work:

myTree.Load("C:\\data\\test\\exam\test.xml")

myTree.Load("C:\\data\test\\exam\\test.xml")

myTree.Load("C:\\data\test\\exam\test.xml")

myTree.Load("C:\\data\test\exam\test.xml")

myTree.Load("C:\data\test\exam\test.xml")

myTree.Load("C:\test.xml")


Cunclusion of my tests:
When using double slashes at any time, I am on the save side, and that is very good to know.

But what to say about the other examples which are working too?
And what is wirred: in some cases it works when putting only single slashes like:

peTree.Load("C:\Studium\SHK\ProjectOrigin\Daten\projektExplorer.xml")


but when I tested with example shown above, in that form it doesnt work.
I would prefer if something either does work, or that it doesnt work.
But when something sometimes in one case does work, and the same thing at anther time doesnt work, I got a problem with that. ;D

Perhabs I should forget about that and stop thinking about, and just use double slashes and everything will be okay.
Even when folder is called "XML" :

( myTree.Load("C:\\XML\\test.xml")


I dont get a "Runtime Error!" anymore.

Thanks for this advice again!



<!-- helping each other is a good thing...like TreeNode holding the leaves of a Tree -->
Go to Top of Page

TreeNode

64 Posts

Posted - 10/31/2009 :  07:02:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Me again.

Think I found the answer:
Its because of the escape sequences right?

\n, \t, and so on...

Thats why in some cases the double slash is required, and in some not.
Like in my testing example:

myTree.Load("C:\\data\\test\\exam\\test.xml")


there have to stand a double slash absolutly before the words "test".

But what about when saving the filepath in a labtalk string variable:

getfile *.xml;
filename$ = %A;
filepath$ = %B;


when typing in scriptwindow:

filepath$=


it returns in this example the string: C:\data\test\exam
You see, with only single slashes.

Anyhow when now calling the function:

void test_load_xml(string filename, string filepath) {
    Tree myTree;
    if( myTree.Load(filepath + filename) ) {
        out_tree(myTree);
    }
    else {
        out_str("File could not be load!");
    }
}


with typing in scriptwindow:

void_test_load(filename$, filepath$)


it works properly. Why arent single slashes not a problem in that case?

<!-- helping each other is a good thing...like TreeNode holding the leaves of a Tree -->

Edited by - TreeNode on 10/31/2009 07:07:40 AM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 10/31/2009 :  09:03:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
LabTalk does not use C escape.

In your C code, when you use string literal, then you need to use '\' to protect the \ in file path.

CP
Go to Top of Page

TreeNode

64 Posts

Posted - 10/31/2009 :  09:42:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi cpyang,

thats a good explanation.
I think I understand.

Thank you very much!

<!-- helping each other is a good thing...like TreeNode holding the branches and leaves of a Tree -->
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000