timport xml into a table

ext.zxmulvps001
Posts: 6
Joined: Mon Jan 28, 2002 12:14 pm

timport xml into a table

Post by ext.zxmulvps001 »

hi all,
first of i'd like to tell you i'm a newbie and that my mother tongue is not english so feel free to correct me.
i'd like to use timport to parse to xml file and load the data into the table "options" of a datbase but it's not working.

here's the data :

<?xml version="1.0" encoding="ISO-8859-1"?>
<BaseWebinator Subject="DBNAME">
<Profile Subject="Profile1">
<name Option="x">/whatsnew.jsp</Name>
<Name Option="x">/whatsnew1.jsp</Name>
<Name Option="Domain"></Name>
<Name Option="Network"></Name>
<Name Option="Proxy"></Name>
<Name Option="dns">sys</Name>
<Name Option="a"></Name>
<Name Option="j"></Name>
<Name Option="C"></Name>
<Name Option="b">CHECKED</Name>
<Name Option="N"></Name>
<name Option="f">htm</Name>
<Name Option="f">txt</Name>
<Name Option="f">jsp</Name>
<Name Option="f">doc</Name>
<name Option="Depthlimit"></Name>
<Name Option="M">3.0</Name>
</Profile>
<Profile Subject="Profile2">
<name Option="Network"></Name>
<Name Option="Proxy"></Name>
<Name Option="dns">sys</Name>
<Name Option="a"></Name>
<Name Option="j"></Name>
<Name Option="C"></Name>
<Name Option="o"></Name>
<Name Option="y"></Name>
<Name Option="r"></Name>
<Name Option="b">CHECKED</Name>
<Name Option="N">CHECKED</Name>
...
</Profile>
<Profile Subject="Profile3">
...
</Profile>
<Profile Subject="Profile4">
...
</Profile>
...
</BaseWebinator>

here's the schema file :
database /data/DBNAME
table options
trimspace
xml nohtml
multiple
field Profile varchar BASEWEBINATOR/PROFILE@Subject
field Name varchar BASEWEBINATOR/PROFILE/NAME@Option
field String varchar BASEWEBINATOR/PROFILE/NAME

when i use this code :

<LOCAL xmlProfilBDSchema xmlProfilBDFile>
<read $PATH_PROFILBDSCHEMA>
<$xmlProfilBDSchema = $ret>
<sum "%s" $path "\" $Db ".xml">
<$fichierXML = $ret>
<read $fichierXML>
<$xmlProfilBDFile = $ret>
<timport $xmlProfilBDSchema $xmlProfilBDFile>
</timport>

nothing happens. The table options is not loaded from the xml.

any help would be greatly appreciated.
thanks in advance
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

timport xml into a table

Post by mark »

Timport's xml parser prefers consistency in the case of tag names. Sometimes you use "Name" and others "name". In any event it's probably not going to do what you want in this case. It will collect all of same tagged values into one variable and give you back one record for an entire profile. What you'll probably want to do is parse with nested timport. Something like this:

<timport row 'recexpr >><Profile Subject\="=[^"]+">=!</Profile>+</Profile>
field Profile varchar 2
field Profiledata varchar 4
' $data>
<timport row 'recexpr >><Name Option\="=[^"]+">=!</Name>*</Name>
field Name varchar 2
field String varchar 4
' $Profiledata>
$Profile,$Name,$String
</timport>
</timport>
ext.zxmulvps001
Posts: 6
Joined: Mon Jan 28, 2002 12:14 pm

timport xml into a table

Post by ext.zxmulvps001 »

For "name", it was a bug, the correct spelling is "Name". You're correct, i don't want the result into one variable. I want to be able to use all the value to insert them into the table options of my database. I Don't understand the syntax you're using for the timport. Are you describing the schema inside the timport between the quotes ? what are the two numbers 2 and 4 for? I've assigned to $data the content of the xml file but when i execute the nested loop nothing prints for $Profile nor $Name nor $String. Am I missing something else?
thanks in advance
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

timport xml into a table

Post by mark »

Yes, the schema is inline as a constant instead of a variable. 2 and 4 are the subexpression numbers. See http://thunderstone.master.com/texis/ma ... cexpr&s=SS .

Make sure you don't have any transcription errors or that cut&paste did not add any whitespace to the end of the lines. recexpr is sensitive to spaces.
ext.zxmulvps001
Posts: 6
Joined: Mon Jan 28, 2002 12:14 pm

timport xml into a table

Post by ext.zxmulvps001 »

it's working !!
THANKS A LOT