automatically create fields from xml tree

Bob Hartley rev at armbase.com
Thu Jan 6 13:13:36 EST 2005


At 23:28 05/01/2005, you wrote:

>Bob,
>
>It depends on what your XML structure looks like: For instance if your XML 
>looks like:


Hi Chipp.

Well I gave this a try and made sure the text.xml file was in the same 
directory.

It originally looked like this

<Database Version="6.0">
         <Rec ID="217089" Arc="1" Dirty="1" Delete="1">
                 <Field ID="GENR">Comedy</Field>
                 <Field ID="TITL">Big Fishies</Field>
                 <Field ID="RATG">PG-13</Field>
                 <Field ID="YEAR">2003</Field>
                 <Field ID="SEEN" Type="1">1</Field>
         </Rec>
         <Rec ID="217090">
                 <Field ID="GENR">Comedy</Field>
                 <Field ID="TITL">Two Weeks Notice</Field>
                 <Field ID="RATG">PG-13</Field>
                 <Field ID="YEAR">2002</Field>
                 <Field ID="SEEN" Type="1">0</Field>
         </Rec>
         <Rec ID="217091">
                 <Field ID="GENR">Drama</Field>
                 <Field ID="TITL">Road to Perdition</Field>
                 <Field ID="RATG">R</Field>
                 <Field ID="YEAR">2002</Field>
                 <Field ID="SEEN" Type="1">1</Field>
         </Rec>
</Database>
  and I eddited it to look like this

<Field>Comedy</Field>
<Field>Big Fishies</Field>
<Field>PG-13</Field>
<Field>2003</Field>
<Field>1</Field>


Then tried the script in button but it did not do anything




><field>Name</field>
><field>Address 1</field>
><field>Address 2</field>
><field>City</field>
><field>State</field>
><button>Cancel</button>
>
>Then have the script of a btn
>
>on mouseUp
>   put URL("file:text.xml") into tXML
>   repeat for each line L in tXML
>     put getTag(L) into tTagName
>     switch tTagName
>     case "field"
>       create field getTagData(L,"field")
>       break
>     case "button"
>       create button getTagData(L,"button")
>       break
>     end switch
>   end repeat
>end mouseUp
>
>function getTagData pTagData,pTagName
>   filter pTagData with "<" & pTagName & ">*"
>   replace "<" & pTagName & ">" with "" in pTagData
>   replace "</" & pTagName & ">" with "" in pTagData
>   return pTagData
>end getTagData
>
>function getTag pStr
>   put offset("<",pStr) into tStart
>   put offset(">",pStr) into tEnd
>   return char tStart+1 to tEnd-1 of pStr
>end getTag


I then changed the script to

function getTagData pTagData,pTagName
filter pTagData with "<" & pTagName & ">*"
replace "<" & pTagName & ">" with "" in pTagData
replace "</" & pTagName & ">" with "" in pTagData
return pTagData
end getTagData
function getTag pStr
   put offset("<",pStr) into tStart
   put offset(">",pStr) into tEnd
   return char tStart+1 to tEnd-1 of pStr
end getTag

on mouseUp
   put URL("file:text.xml") into tXML
   repeat for each line L in tXML
     put getTag(L) into tTagName
     switch tTagName
     case "field"
       create field getTagData(L,"field")
       break
     case "button"
       create button getTagData(L,"button")
       break
     end switch
   end repeat
end mouseUp

Just in case it needed the function before the on mouseup handler.

Still no luck.

I'll have a go later in the weekend.

cheers
bob



>This will create a field for each field element and a button for each 
>button element.
>
>Hope that helps,
>
>Chipp
>
>
>Bob Hartley wrote:
>>Hi all.
>>Is it possible to automatically create fields from an xml tree using the 
>>runrev xml commands or do I need to know the names of the xml items?
>
>
>--
>No virus found in this outgoing message.
>Checked by AVG Anti-Virus.
>Version: 7.0.298 / Virus Database: 265.6.7 - Release Date: 12/30/2004
>
>_______________________________________________
>use-revolution mailing list
>use-revolution at lists.runrev.com
>http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
>
>--
>No virus found in this incoming message.
>Checked by AVG Anti-Virus.
>Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 03/01/2005


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.8 - Release Date: 03/01/2005




More information about the use-livecode mailing list