Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use QM to quickly modify the keys and values ​​in a plist file
#11
need to use x.Path to find the location
 has previous example plus new 1
Function IxmlExample2 
Code:
Copy      Help
IXml x._create
x.FromFile("$desktop$\plist_file\file.plist")
int t tt
ARRAY(IXmlNode) a b c; int i
x.RootElement.GetAll(0 a)
for i 0 a.len
,IXmlNode n=a[i]
,if(!StrCompare(n.Value "key20"))
,,t=1
,if(!StrCompare(n.Value "key7"))
,,n=n.Next
,,if(!StrCompare(n.Name "false"))
,,,n.Name="true"
,if(!StrCompare(n.Value "key9"))
,,x.Delete(n);; remove <key>key9</key>
,,n=a[i+1]
,,if(!StrCompare(n.Name "string"))
,,,x.Delete(n);; remove <string>string6</string>
if(t!=1)
,x.Path("plist/dict/dict").GetAll(0 b)
,for i 0 b.len
,,sel b[i].Name
,,,case "key"
,,,if(!StrCompare(b[i].Value "key5"))
,,,,IXmlNode iafter
,,,,iafter=b[i+1]
,,,,b[i].Parent.Insert(iafter "string" "string20")
,,,,b[i].Parent.Insert(iafter "key" "key20")    
x.ToString(_s)
out _s
x.Path("plist/dict/dict/[key='key5']/array").GetAll(0 c)
for i 0 c.len
,n=c[i]
,if(!StrCompare(n.Name "string"))
,,x.Delete(n);; removes all <string>string*</string> from <key>key5</key>
n=x.Path("plist/dict/dict/[key='key5']/array");; path to key5 array
n.Add("dict" "").Add("key" "Comment").Parent.Add("string" "Comment1").Parent.Add("key" "Disabled").Parent.Add("true").Parent.Add("key" "Find").Parent.Add("data" "Comment1").Parent.Add("key" "Replace").Parent.Add("data" "Comment1+")
n.Add("dict" "").Add("key" "Comment").Parent.Add("string" "Comment2").Parent.Add("key" "Disabled").Parent.Add("true").Parent.Add("key" "Find").Parent.Add("data" "Comment2").Parent.Add("key" "Replace").Parent.Add("data" "Comment2+")
n.Add("dict" "").Add("key" "Comment").Parent.Add("string" "Comment3").Parent.Add("key" "Disabled").Parent.Add("true").Parent.Add("key" "Find").Parent.Add("data" "Comment3").Parent.Add("key" "Replace").Parent.Add("data" "Comment3+")
IXmlNode e=x.Path("plist/dict/dict/string[='string20']");; path to <string>string20</string>
e.Value=""
e.Name="array";; change <string>string20</string> to <array></array>
;adds new data to <key>key20</key> <array>*data added here</array>
e.Add("dict" "").Add("key" "Comment").Parent.Add("string" "Comment1").Parent.Add("key" "Disabled").Parent.Add("true").Parent.Add("key" "Find").Parent.Add("data" "Comment1").Parent.Add("key" "Replace").Parent.Add("data" "Comment1+")
e.Add("dict" "").Add("key" "Comment").Parent.Add("string" "Comment2").Parent.Add("key" "Disabled").Parent.Add("true").Parent.Add("key" "Find").Parent.Add("data" "Comment2").Parent.Add("key" "Replace").Parent.Add("data" "Comment2+")
e.Add("dict" "").Add("key" "Comment").Parent.Add("string" "Comment3").Parent.Add("key" "Disabled").Parent.Add("true").Parent.Add("key" "Find").Parent.Add("data" "Comment3").Parent.Add("key" "Replace").Parent.Add("data" "Comment3+")

x.ToString(_s)
out _s
x.ToFile("$desktop$\plist_file\file.plist")


Messages In This Thread
RE: use QM to quickly modify the keys and values ​​in a plist file - by Kevin - 08-21-2018, 06:51 PM

Forum Jump:


Users browsing this thread: 4 Guest(s)