revXMLNodeContents to DataGrid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
gilar
Posts: 78
Joined: Sat Sep 26, 2015 12:59 pm

revXMLNodeContents to DataGrid

Post by gilar » Mon Sep 17, 2018 5:13 pm

Hello every body ....
I have been trying to grab content of XML
and i Have successed with this code

Code: Select all

on mouseUp
   put url "file:D:/ASIAN-PARA GAMES/Asset/For Broadcast XML/Basketball Xml/teams.xml" into tURL
   put revCreateXMLTree(tURL, false, true, false) into tDocID
   put revXMLNodeContents(tDocID,"xml/teams/players/familyName") into  tResult
   put tResult into field hasil_fld
end mouseUp
The question is how to get XML content which has the same tag
Let say i have a list of player name in XML file
and i want to grab all into a text field or dataGrid
but i'm a little bit confuse, because the xml has a same tag for player

This is the XML sample
https://drive.google.com/open?id=18WMdf ... mDuM4jdUus

Comment and help would be appriciate


Gilar Kadarsah
Last edited by gilar on Wed Sep 19, 2018 5:42 am, edited 1 time in total.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1763
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: How to Get conten of XML with the same Tag

Post by [-hh] » Mon Sep 17, 2018 8:40 pm

There is no "special-for-XML" support in LC for that.

But this is an ordinary text search.
You could simply use the tags as itemdelimiter and linedelimiter.
For example:

Code: Select all

on mouseUp
   put url ("file:D:/ASIAN-PARA GAMES/Asset/For Broadcast XML/Basketball Xml/teams.xml") into txt
   put extractTags(txt, "<pno>","</pno>") into fld "numbers"
   put extractTags(txt, "<familyName>","</familyName>") into fld "familyNames"
   --> etc ...
end mouseUp

function extractTags txt, tag1,tag2
   if tag1 is not in txt then return empty
   set linedelimiter  to  tag1
   set itemdelimiter to  tag2
   repeat for each line L in tURL
        put (item 1 of L) & CR after tOut
   end repeat
   -- because we start with line 2 of the input
   -- we ignore the first line (and the last CR)
   return line 2 to -2 of tOut
end extractTags
Then you can align the fieldsand do a simultan scroll.
Or put the values in array for further evaluation ...

HTH.
shiftLock happens

gilar
Posts: 78
Joined: Sat Sep 26, 2015 12:59 pm

Re: How to Get conten of XML with the same Tag

Post by gilar » Tue Sep 18, 2018 3:37 am

Hi -hh ... thanks for replay ...
I just try your code but nothing happen in livecode...

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1763
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: How to Get conten of XML with the same Tag

Post by [-hh] » Tue Sep 18, 2018 7:53 am

I made a mistake, sorry (the code was right out of my head).
It works here now with the exactly formatted XML-sample of your link as input.
So change the code to the following.

Code: Select all

on mouseUp
  put url ("file:D:/ASIAN-PARA GAMES/Asset/For Broadcast XML/Basketball Xml/teams.xml") into tURL
  replace linefeed with empty in tURL --> in case we have windows CRLF
  put extractTags(tURL, "<pno>","</pno>") into fld "numbers"
  put extractTags(tURL, "<familyName>","</familyName>") into fld "familyNames"
  --> etc ...
end mouseUp

function extractTags txt, tag1,tag2
  if tag1 is not in txt then return empty
  set linedelimiter to  tag1
  set itemdelimiter to  tag2
  repeat for each line L in txt
    put (item 1 of L) & CR after tOut
  end repeat
  -- because we start with line 2 of the input
  -- we ignore the first line (and the last CR)
  set linedelimiter to CR
  return line 2 to -2 of tOut
end extractTags
If it doesn't work try to add your two revXML lines for an more exact format.
shiftLock happens

gilar
Posts: 78
Joined: Sat Sep 26, 2015 12:59 pm

Re: revXMLNodeContents to DataGrid

Post by gilar » Wed Sep 19, 2018 6:02 am

I'm follow this Tutorial https://drive.google.com/drive/folders/ ... 3RPc2x2N1k
and make same modify code

finnally i can get the conten of XML with revXMLNodeContents and populate into DataGrid
for anyone who has the same problem with me
Hope it will give you some direction to your problem ....

Code: Select all

local sXMLID

on mouseUp
   createTree
   populateFieldsHomeTeam
   populateFieldsAwayTeam
end mouseUp

on createTree
   put url ("file:G:/PRODUCT/TRIAL AND ERROR/reading xml/XML file/teams_edit.xml") into tXMLData
   put revCreateXMLTree(tXMLData, true, true, true, true) into sXMLID
end createTree

on populateFieldsHomeTeam
   --- Nomer Punggung
   put revXMLNodeContents(sXMLID, "xml/teams/players[1]/pno") into tNo1
   put revXMLNodeContents(sXMLID, "xml/teams/players[2]/pno") into tNo2
   put revXMLNodeContents(sXMLID, "xml/teams/players[3]/pno") into tNo3
   put revXMLNodeContents(sXMLID, "xml/teams/players[4]/pno") into tNo4
   put revXMLNodeContents(sXMLID, "xml/teams/players[5]/pno") into tNo5
   put revXMLNodeContents(sXMLID, "xml/teams/players[6]/pno") into tNo6
   put revXMLNodeContents(sXMLID, "xml/teams/players[7]/pno") into tNo7
   put revXMLNodeContents(sXMLID, "xml/teams/players[8]/pno") into tNo8
   put revXMLNodeContents(sXMLID, "xml/teams/players[9]/pno") into tNo9
   put revXMLNodeContents(sXMLID, "xml/teams/players[10]/pno") into tNo10
   put revXMLNodeContents(sXMLID, "xml/teams/players[11]/pno") into tNo11
   put revXMLNodeContents(sXMLID, "xml/teams/players[12]/pno") into tNo12
   --- FirstName
   put revXMLNodeContents(sXMLID, "xml/teams/players[1]/firstName") into tFirstName1
   put revXMLNodeContents(sXMLID, "xml/teams/players[2]/firstName") into tFirstName2
   put revXMLNodeContents(sXMLID, "xml/teams/players[3]/firstName") into tFirstName3
   put revXMLNodeContents(sXMLID, "xml/teams/players[4]/firstName") into tFirstName4
   put revXMLNodeContents(sXMLID, "xml/teams/players[5]/firstName") into tFirstName5
   put revXMLNodeContents(sXMLID, "xml/teams/players[6]/firstName") into tFirstName6
   put revXMLNodeContents(sXMLID, "xml/teams/players[7]/firstName") into tFirstName7
   put revXMLNodeContents(sXMLID, "xml/teams/players[8]/firstName") into tFirstName8
   put revXMLNodeContents(sXMLID, "xml/teams/players[9]/firstName") into tFirstName9
   put revXMLNodeContents(sXMLID, "xml/teams/players[10]/firstName") into tFirstName10
   put revXMLNodeContents(sXMLID, "xml/teams/players[11]/firstName") into tFirstName11
   put revXMLNodeContents(sXMLID, "xml/teams/players[12]/firstName") into tFirstName12
   
   put revXMLNodeContents(sXMLID, "xml/teams/coach[1]/firstName") into tCFirstName1
   put revXMLNodeContents(sXMLID, "xml/teams/assistcoach1[1]/firstName") into tCFirstName2
   put revXMLNodeContents(sXMLID, "xml/teams/assistcoach2[1]/firstName") into tCFirstName3
   ---- FamilyName
   put revXMLNodeContents(sXMLID, "xml/teams/players[1]/familyName") into tFamilyName1
   put revXMLNodeContents(sXMLID, "xml/teams/players[2]/familyName") into tFamilyName2
   put revXMLNodeContents(sXMLID, "xml/teams/players[3]/familyName") into tFamilyName3
   put revXMLNodeContents(sXMLID, "xml/teams/players[4]/familyName") into tFamilyName4
   put revXMLNodeContents(sXMLID, "xml/teams/players[5]/familyName") into tFamilyName5
   put revXMLNodeContents(sXMLID, "xml/teams/players[6]/familyName") into tFamilyName6
   put revXMLNodeContents(sXMLID, "xml/teams/players[7]/familyName") into tFamilyName7
   put revXMLNodeContents(sXMLID, "xml/teams/players[8]/familyName") into tFamilyName8
   put revXMLNodeContents(sXMLID, "xml/teams/players[9]/familyName") into tFamilyName9
   put revXMLNodeContents(sXMLID, "xml/teams/players[10]/familyName") into tFamilyName10
   put revXMLNodeContents(sXMLID, "xml/teams/players[11]/familyName") into tFamilyName11
   put revXMLNodeContents(sXMLID, "xml/teams/players[12]/familyName") into tFamilyName12
   
   put revXMLNodeContents(sXMLID, "xml/teams/coach[1]/familyName") into tCFamilyName1
   put revXMLNodeContents(sXMLID, "xml/teams/assistcoach1[1]/familyName") into tCFamilyName2
   put revXMLNodeContents(sXMLID, "xml/teams/assistcoach2[1]/familyName") into tCFamilyName3
   --- Team A
   --- NoPunggung
   put tNo1 into theDataA[ 1 ][ "No" ]
   put tNo2 into theDataA[ 2 ][ "No" ]
   put tNo3 into theDataA[ 3 ][ "No" ]
   put tNo4 into theDataA[ 4 ][ "No" ]
   put tNo5 into theDataA[ 5 ][ "No" ]
   put tNo6 into theDataA[ 6 ][ "No" ]
   put tNo7 into theDataA[ 7 ][ "No" ]
   put tNo8 into theDataA[ 8 ][ "No" ]
   put tNo9 into theDataA[ 9 ][ "No" ]
   put tNo10 into theDataA[ 10 ][ "No" ]
   put tNo11 into theDataA[ 11 ][ "No" ]
   put tNo12 into theDataA[ 12 ][ "No" ]
   put empty into theDataA[ 13 ][ "No" ]
   --- FirstName
   put tFirstName1 into theDataA[ 1 ][ "FirstName" ]
   put tFirstName2 into theDataA[ 2 ][ "FirstName" ]
   put tFirstName3 into theDataA[ 3 ][ "FirstName" ]
   put tFirstName4 into theDataA[ 4 ][ "FirstName" ]
   put tFirstName5 into theDataA[ 5 ][ "FirstName" ]
   put tFirstName6 into theDataA[ 6 ][ "FirstName" ]
   put tFirstName7 into theDataA[ 7 ][ "FirstName" ]
   put tFirstName8 into theDataA[ 8 ][ "FirstName" ]
   put tFirstName9 into theDataA[ 9 ][ "FirstName" ]
   put tFirstName10 into theDataA[ 10 ][ "FirstName" ]
   put tFirstName11 into theDataA[ 11 ][ "FirstName" ]
   put tFirstName12 into theDataA[ 12 ][ "FirstName" ]
   put empty into theDataA[ 13 ][ "FirstName" ]
   put tCFirstName1 into theDataA[ 14 ][ "FirstName" ]
   put tCFirstName2 into theDataA[ 15 ][ "FirstName" ]
   put tCFirstName3 into theDataA[ 16 ][ "FirstName" ]
   --- FamilyName
   put tFamilyName1 into theDataA[ 1 ][ "FamilyName" ]
   put tFamilyName2 into theDataA[ 2 ][ "FamilyName" ]
   put tFamilyName3 into theDataA[ 3 ][ "FamilyName" ]
   put tFamilyName4 into theDataA[ 4 ][ "FamilyName" ]
   put tFamilyName5 into theDataA[ 5 ][ "FamilyName" ]
   put tFamilyName6 into theDataA[ 6 ][ "FamilyName" ]
   put tFamilyName7 into theDataA[ 7 ][ "FamilyName" ]
   put tFamilyName8 into theDataA[ 8 ][ "FamilyName" ]
   put tFamilyName9 into theDataA[ 9 ][ "FamilyName" ]
   put tFamilyName10 into theDataA[ 10 ][ "FamilyName" ]
   put tFamilyName11 into theDataA[ 11 ][ "FamilyName" ]
   put tFamilyName12 into theDataA[ 12 ][ "FamilyName" ]
   put empty into theDataA[ 13 ][ "FamilyName" ]
   put tCFamilyName1 into theDataA[ 14 ][ "FamilyName" ]
   put tCFamilyName2 into theDataA[ 15 ][ "FamilyName" ]
   put tCFamilyName3 into theDataA[ 16 ][ "FamilyName" ]
   
   set the dgData of group "DataGrid 2" to theDataA
   
end populateFieldsHomeTeam

on populateFieldsAwayTeam
   --- Nomer Punggung
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[1]/pno") into tNo1
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[2]/pno") into tNo2
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[3]/pno") into tNo3
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[4]/pno") into tNo4
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[5]/pno") into tNo5
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[6]/pno") into tNo6
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[7]/pno") into tNo7
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[8]/pno") into tNo8
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[9]/pno") into tNo9
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[10]/pno") into tNo10
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[11]/pno") into tNo11
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[12]/pno") into tNo12
   --- FirstName
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[1]/firstName") into tFirstName1
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[2]/firstName") into tFirstName2
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[3]/firstName") into tFirstName3
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[4]/firstName") into tFirstName4
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[5]/firstName") into tFirstName5
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[6]/firstName") into tFirstName6
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[7]/firstName") into tFirstName7
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[8]/firstName") into tFirstName8
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[9]/firstName") into tFirstName9
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[10]/firstName") into tFirstName10
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[11]/firstName") into tFirstName11
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[12]/firstName") into tFirstName12
   
   put revXMLNodeContents(sXMLID, "xml/teams[2]/coach[1]/firstName") into tCFirstName1
   put revXMLNodeContents(sXMLID, "xml/teams[2]/assistcoach1[1]/firstName") into tCFirstName2
   put revXMLNodeContents(sXMLID, "xml/teams[2]/assistcoach2[1]/firstName") into tCFirstName3
   ---- FamilyName
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[1]/familyName") into tFamilyName1
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[2]/familyName") into tFamilyName2
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[3]/familyName") into tFamilyName3
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[4]/familyName") into tFamilyName4
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[5]/familyName") into tFamilyName5
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[6]/familyName") into tFamilyName6
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[7]/familyName") into tFamilyName7
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[8]/familyName") into tFamilyName8
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[9]/familyName") into tFamilyName9
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[10]/familyName") into tFamilyName10
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[11]/familyName") into tFamilyName11
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[12]/familyName") into tFamilyName12
   
   put revXMLNodeContents(sXMLID, "xml/teams[2]/coach[1]/familyName") into tCFamilyName1
   put revXMLNodeContents(sXMLID, "xml/teams[2]/assistcoach1[1]/familyName") into tCFamilyName2
   put revXMLNodeContents(sXMLID, "xml/teams[2]/assistcoach2[1]/familyName") into tCFamilyName3
   --- Team A
   --- NoPunggung
   put tNo1 into theDataA[ 1 ][ "No" ]
   put tNo2 into theDataA[ 2 ][ "No" ]
   put tNo3 into theDataA[ 3 ][ "No" ]
   put tNo4 into theDataA[ 4 ][ "No" ]
   put tNo5 into theDataA[ 5 ][ "No" ]
   put tNo6 into theDataA[ 6 ][ "No" ]
   put tNo7 into theDataA[ 7 ][ "No" ]
   put tNo8 into theDataA[ 8 ][ "No" ]
   put tNo9 into theDataA[ 9 ][ "No" ]
   put tNo10 into theDataA[ 10 ][ "No" ]
   put tNo11 into theDataA[ 11 ][ "No" ]
   put tNo12 into theDataA[ 12 ][ "No" ]
   put empty into theDataA[ 13 ][ "No" ]
   --- FirstName
   put tFirstName1 into theDataA[ 1 ][ "FirstName" ]
   put tFirstName2 into theDataA[ 2 ][ "FirstName" ]
   put tFirstName3 into theDataA[ 3 ][ "FirstName" ]
   put tFirstName4 into theDataA[ 4 ][ "FirstName" ]
   put tFirstName5 into theDataA[ 5 ][ "FirstName" ]
   put tFirstName6 into theDataA[ 6 ][ "FirstName" ]
   put tFirstName7 into theDataA[ 7 ][ "FirstName" ]
   put tFirstName8 into theDataA[ 8 ][ "FirstName" ]
   put tFirstName9 into theDataA[ 9 ][ "FirstName" ]
   put tFirstName10 into theDataA[ 10 ][ "FirstName" ]
   put tFirstName11 into theDataA[ 11 ][ "FirstName" ]
   put tFirstName12 into theDataA[ 12 ][ "FirstName" ]
   put empty into theDataA[ 13 ][ "FirstName" ]
   put tCFirstName1 into theDataA[ 14 ][ "FirstName" ]
   put tCFirstName2 into theDataA[ 15 ][ "FirstName" ]
   put tCFirstName3 into theDataA[ 16 ][ "FirstName" ]
   --- FamilyName
   put tFamilyName1 into theDataA[ 1 ][ "FamilyName" ]
   put tFamilyName2 into theDataA[ 2 ][ "FamilyName" ]
   put tFamilyName3 into theDataA[ 3 ][ "FamilyName" ]
   put tFamilyName4 into theDataA[ 4 ][ "FamilyName" ]
   put tFamilyName5 into theDataA[ 5 ][ "FamilyName" ]
   put tFamilyName6 into theDataA[ 6 ][ "FamilyName" ]
   put tFamilyName7 into theDataA[ 7 ][ "FamilyName" ]
   put tFamilyName8 into theDataA[ 8 ][ "FamilyName" ]
   put tFamilyName9 into theDataA[ 9 ][ "FamilyName" ]
   put tFamilyName10 into theDataA[ 10 ][ "FamilyName" ]
   put tFamilyName11 into theDataA[ 11 ][ "FamilyName" ]
   put tFamilyName12 into theDataA[ 12 ][ "FamilyName" ]
   put empty into theDataA[ 13 ][ "FamilyName" ]
   put tCFamilyName1 into theDataA[ 14 ][ "FamilyName" ]
   put tCFamilyName2 into theDataA[ 15 ][ "FamilyName" ]
   put tCFamilyName3 into theDataA[ 16 ][ "FamilyName" ]
   
   set the dgData of group "DataGrid 3" to theDataA
end populateFieldsAwayTeam

There is one more question, maybe anyone could help me
Is it imposssible to make mycode sorter
i mean can we make this code sorter with repeat fungction

Code: Select all

   put tFamilyName1 into theDataA[ 1 ][ "FamilyName" ]
   put tFamilyName2 into theDataA[ 2 ][ "FamilyName" ]
   put tFamilyName3 into theDataA[ 3 ][ "FamilyName" ]
   put tFamilyName4 into theDataA[ 4 ][ "FamilyName" ]
   put tFamilyName5 into theDataA[ 5 ][ "FamilyName" ]
   put tFamilyName6 into theDataA[ 6 ][ "FamilyName" ]
   put tFamilyName7 into theDataA[ 7 ][ "FamilyName" ]
   put tFamilyName8 into theDataA[ 8 ][ "FamilyName" ]
   put tFamilyName9 into theDataA[ 9 ][ "FamilyName" ]
   put tFamilyName10 into theDataA[ 10 ][ "FamilyName" ]
   put tFamilyName11 into theDataA[ 11 ][ "FamilyName" ]
   put tFamilyName12 into theDataA[ 12 ][ "FamilyName" ]

Comment and help wouldbe appriciate


Best Regards

Gilar Kadarsah

Klaus
Posts: 10327
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: revXMLNodeContents to DataGrid

Post by Klaus » Wed Sep 19, 2018 12:23 pm

Hi Gilar,

unfortunately we can only deal with variable names like this in a DO statement.
Which is not very effective by the way, means much slower that direct scripting.
It goes like this:
...
repeat with i = 1 to 12
do ("put tFamilyName" & i && "into theData[" & i & "][" & "FamilyName" & "]")
end repeat
...
It is ugly, hard to read and error prone, I had to change the order of brackets about ten times before the engine stopped to complain! 8)

Can't you fill the Array when you are populating all these tFamiliNameX variables?


Best

Klaus

gilar
Posts: 78
Joined: Sat Sep 26, 2015 12:59 pm

Re: revXMLNodeContents to DataGrid

Post by gilar » Wed Sep 19, 2018 6:10 pm

Hi Klaus .... you again.
Thank You very much ....

Your code work like a charm ... love it.

Code: Select all

   repeat with i = 1 to 12
      do ("put tFamilyName" & i && "into theDataA[" & i & "][" & "FamilyName" & "]")
   end repeat
Now I'm trying to do the same way for this

Code: Select all

   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[1]/pno") into tNo1
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[2]/pno") into tNo2
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[3]/pno") into tNo3
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[4]/pno") into tNo4
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[5]/pno") into tNo5
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[6]/pno") into tNo6
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[7]/pno") into tNo7
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[8]/pno") into tNo8
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[9]/pno") into tNo9
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[10]/pno") into tNo10
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[11]/pno") into tNo11
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[12]/pno") into tNo12
But i found proublem with double quote

Code: Select all

   repeat with i = 1 to 12
      do ("put revXMLNodeContents(sXMLID, " & "xml/teams/players[" & i & "]/pno" & ") into tNo& i &")
   end repeat
i think this is my problem.
I can not write double quote on script do .....

Code: Select all

---- "xml/teams[2]/players[1]/pno"
change to --- ---- &quote&"xml/teams[2]/players[" & i & "]/pno"&quote&
It is ugly, hard to read and error prone, I had to change the order of brackets about ten times before the engine stopped to complain! 8)
Is there anotther simple way to do this?
Can't you fill the Array when you are populating all these tFamiliNameX variables?

So far ... all XML data populate into DataGrid


Best Regards



Gilar Kadarsah

Klaus
Posts: 10327
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: revXMLNodeContents to DataGrid

Post by Klaus » Wed Sep 19, 2018 6:43 pm

Hi Gilar,

I meant to fill the array for the datagrid directly in your XML repeat loop without using millions of variables. Like this in one loop:

Code: Select all

local sXMLID

local theDataA 
## if neccessary

on populateFieldsHomeTeam
   repeat with i = 1 to 12
      put revXMLNodeContents(sXMLID, "xml/teams/players[" & i & "]/pno") into theDataA[i]["playernumber"]
      ## or how this key is named
      
      put revXMLNodeContents(sXMLID, "xml/teams/players[" & i & "]/firstName") into theDataA[i]["firstname"]
      put revXMLNodeContents(sXMLID, "xml/teams/players[" & i & "]/familyName") into theDataA [i]["familyname"]
      ## etc...
   end repeat
end populateFieldsHomeTeam
Know what I mean?


Best

Klaus

gilar
Posts: 78
Joined: Sat Sep 26, 2015 12:59 pm

Re: revXMLNodeContents to DataGrid

Post by gilar » Wed Sep 19, 2018 7:09 pm

Hi Klause ..... finally i can solve this problem

Code: Select all

 put revXMLNodeContents(sXMLID, "xml/teams[2]/players[1]/pno") into tNo1
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[2]/pno") into tNo2
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[3]/pno") into tNo3
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[4]/pno") into tNo4
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[5]/pno") into tNo5
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[6]/pno") into tNo6
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[7]/pno") into tNo7
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[8]/pno") into tNo8
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[9]/pno") into tNo9
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[10]/pno") into tNo10
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[11]/pno") into tNo11
   put revXMLNodeContents(sXMLID, "xml/teams[2]/players[12]/pno") into tNo12
with this code

Code: Select all

   repeat with i = 1 to 12
      do ("put revXMLNodeContents(sXMLID, " & quote & "xml/teams/players[" & i & "]/pno"& quote &") into tNo" & i & "")
   end repeat

gilar
Posts: 78
Joined: Sat Sep 26, 2015 12:59 pm

Re: revXMLNodeContents to DataGrid

Post by gilar » Wed Sep 19, 2018 7:15 pm

Klaus wrote:
Wed Sep 19, 2018 6:43 pm
Hi Gilar,

I meant to fill the array for the datagrid directly in your XML repeat loop without using millions of variables. Like this in one loop:

Code: Select all

local sXMLID

local theDataA 
## if neccessary

on populateFieldsHomeTeam
   repeat with i = 1 to 12
      put revXMLNodeContents(sXMLID, "xml/teams/players[" & i & "]/pno") into theDataA[i]["playernumber"]
      ## or how this key is named
      
      put revXMLNodeContents(sXMLID, "xml/teams/players[" & i & "]/firstName") into theDataA[i]["firstname"]
      put revXMLNodeContents(sXMLID, "xml/teams/players[" & i & "]/familyName") into theDataA [i]["familyname"]
      ## etc...
   end repeat
end populateFieldsHomeTeam
Know what I mean?


Best

Klaus
I just no idea to write that code like what you have done
It looks like more efficent.
Love this ... i will try it.

Thanks a lot

gilar
Posts: 78
Joined: Sat Sep 26, 2015 12:59 pm

Re: revXMLNodeContents to DataGrid

Post by gilar » Wed Sep 19, 2018 7:52 pm

Hi Klaus you are pretty cool ...

your code work like a charm
now i can save much time

Thank you very much
God Bless you

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”