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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 load XML-file into Tree object

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
TreeNode Posted - 10/29/2009 : 1:36:42 PM
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 -->
5   L A T E S T    R E P L I E S    (Newest First)
TreeNode Posted - 10/31/2009 : 09:42:11 AM
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 -->
cpyang Posted - 10/31/2009 : 09:03:44 AM
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
TreeNode Posted - 10/31/2009 : 07:02:48 AM
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 -->
TreeNode Posted - 10/30/2009 : 10:48:02 AM
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 -->
Iris_Bai Posted - 10/30/2009 : 06:11:08 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000