Hi all,
I’m parsing an xml file (using System event) and during the parsing, I’m putting name and value from xml into a data source…
but I did not manage to create a child for my data source within the “tell System Event” block…
Here is the script.
I would be very grateful is some one could help me, or give me advice about things I do wrong.
global dataSource
on awake from nib theObject
-- Processing tree view
if name of theObject is "treeSV" then
-- create the data source
set dataSource to make new data source at end of data sources with properties {name:"Bias"}
-- create the data columns
tell dataSource
make new data column at end of data columns with properties {name:"Bias"}
make new data column at end of data columns with properties {name:"Norm"}
make new data column at end of data columns with properties {name:"Wilcoxon"}
make new data column at end of data columns with properties {name:"Student"}
end tell
-- create first parent (this will be always like that)
set parentItemAC to make new data item with properties {name:"Atomic content"} at end of data items of dataSource
set contents of data cell "Bias" of parentItemAC to "Atomic content"
set contents of data cell "Norm" of parentItemAC to ""
set contents of data cell "Wilcoxon" of parentItemAC to ""
set contents of data cell "Student" of parentItemAC to ""
set parentItemAAC to make new data item with properties {name:"Amino acid content"} at end of data items of dataSource
set contents of data cell "Bias" of parentItemAAC to "Amino acid content"
set contents of data cell "Norm" of parentItemAAC to ""
set contents of data cell "Wilcoxon" of parentItemAAC to ""
set contents of data cell "Student" of parentItemAAC to ""
set parentItemAAP to make new data item with properties {name:"Amino acid parameters"} at end of data items of dataSource
set contents of data cell "Bias" of parentItemAAP to "Amino acid parameters"
set contents of data cell "Norm" of parentItemAAP to ""
set contents of data cell "Wilcoxon" of parentItemAAP to ""
set contents of data cell "Student" of parentItemAAP to ""
set parentItemPP to make new data item with properties {name:"Protein parameters"} at end of data items of dataSource
set contents of data cell "Bias" of parentItemPP to "Protein parameters"
set contents of data cell "Norm" of parentItemPP to ""
set contents of data cell "Wilcoxon" of parentItemPP to ""
set contents of data cell "Student" of parentItemPP to ""
-- getting child from xml parsing of an xml file
-- path to xml file
set xmlFile to (getMyFolder() & "/results.xml")
display dialog "begin XML parsing"
-- get xml data from xml file
set xmlData to getData(xmlFile)
tell application "System Events"
set root to XML element 1 of xmlData
repeat with i from 1 to (count XML element of root)
set lvl1_e to XML element i of root
if (lvl1_e's name is "result") then
repeat with j from 1 to (count XML element of lvl1_e)
set lvl2_e to XML element j of lvl1_e
repeat with k from 1 to (count XML element of lvl2_e)
set lvl3_e to XML element k of lvl2_e
set biasName to ""
set biasNorm to ""
set biasFami to ""
if lvl3_e's name is "biasName" then
set biasName to lvl3_e's value
end if
if lvl3_e's name is "biasNormalization" then
set biasNorm to lvl3_e's value
end if
if lvl3_e's name is "biasFamilly" then
set biasFami to lvl3_e's value
end if
---
--- Here is the problem (biasFami directly refers to the name of one of the four paretn already created)
---
set childItem to make new data item at end of data items of parentItem whose name is biasFami
end repeat
end repeat
end if
end repeat
end tell
display dialog res as string
display dialog "end XML tool"
-- Assign the data source to the outline view
set data source of outline view "treeBias" of scroll view "treeSV" of window "BiasViewer" to dataSource
end if
end awake from nib
on getData(theFile)
set theXmlfile to (POSIX file theFile) as Unicode text
tell application "System Events" to return (contents of XML file theXmlfile)
end getData