Vote count: 0
my xml data dxml := <cm> <id>TASK_DATA_RES</id> <task> <swid>3873-0</swid> <detail> <![CDATA[<execute name="EXECUTE">
type rmsh_rq struct{ ID string
<swid>3873</swid> <tskid>MONITOR0</tskid> <file_name>DiskStatusCheck.ps1</file_name> <param>/metricName::metric_3873_48 /metric::DiskStatusCheck /warn::1 /critical::1 /alert::1 /params::E:</param> <timeout></timeout> <user>test\\test</user> <passwd>test</passwd> <path>http://ift.tt/1kvM13k; <pathtype>local</pathtype> <size>9147</size> <encoded_size>9147</encoded_size> <type>POWERSHELL</type> <outputdir></outputdir> <outputfile></outputfile> <alert>false</alert> <regkeypath></regkeypath> <regkeyval></regkeyval> <process></process> <service></service> <version>5.00</version> <asuser_flag>0</asuser_flag> </execute>]]> </detail> </task> </cm>xml:"id"
Reqid string xml:"reqid"
ScriptCmd string xml:"scriptCmd"
Shellcmd string xml:"sshellcmd"
Params string xml:"params"
}
type detail struct{
Name string `xml:"detail>name"`
Swid string `xml:"detail>swid"`
Tskid string `xml:"detail>tskid"`
File string `xml:"detail>file"`
Param string `xml:"detail>params"`
User string `xml:"detail>user"`
Passwd string `xml:"detail>passwd"`
Path string `xml:"detail>path"`
Pathtype string `xml:"detail>pathtype"`
Size int `xml:"detail>size"`
Encode string `xml:"detail>encode"`
Type string `xml:"detail>type"`
Outputdir string `xml:"detail>outputdir"`
Outputfile string `xml:"detail>outputfile"`
Alert string `xml:"detail>alert"`
Regkeyval string `xml:"detail>regkeyval"`
Process string `xml:"detail>process"`
Service string `xml:"detail>service"`
Version float64 `xml:"detail>version"`
Asuser_flag string `xml:"detail>asuser_flag"`
}
type task struct{
Swid string `xml:"swid"`
Details []detail `xml:"Details>detail"`
}
type task_data_res struct{
ID string `xml:"id"`
//Swid string `xml:"task>swid"`
Tasks []task `xml:"Tasks>task"`
}
v := task_data_res{}
err := xml.Unmarshal([]byte(*dxml), &v)
if err != nil {
fmt.Printf("error: %v", err)
return
}
fmt.Println("ID is ",v.ID)
for i, e := range v.Tasks{
log.Printf("[%2d] %#v\n", i, e)
}
//fmt.Println(" is",v)
fmt.Println("Details swid is",v.SwidD)
fmt.Println("Details TSKID is",v.Tskid)
fmt.Println("Details TSKID is",v.File)
fmt.Println("Details TSKID is",v.Pathtype)
fmt.Println("Details TSKID is",v.Encode)
fmt.Println("Details TSKID is",v.Regkeyval)
fmt.Println("Details TSKID is",v.Asuser_flag)
}
===========================error=========================================
src\xmlfunc\xmlfunc.go:112: v.SwidD undefined (type task_data_res has no field or method SwidD)
src\xmlfunc\xmlfunc.go:113: v.Tskid undefined (type task_data_res has no field or method Tskid)
src\xmlfunc\xmlfunc.go:114: v.File undefined (type task_data_res has no field or method File)
src\xmlfunc\xmlfunc.go:115: v.Pathtype undefined (type task_data_res has no field or method Pathtype)
src\xmlfunc\xmlfunc.go:116: v.Encode undefined (type task_data_res has no field or method Encode)
src\xmlfunc\xmlfunc.go:117: v.Regkeyval undefined (type task_data_res has no field or method Regkeyval)
src\xmlfunc\xmlfunc.go:118: v.Asuser_flag undefined (type task_data_res has no field or method Asuser_flag)
This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.
xml parsing in golang (i want to access each element in the details individually )
Aucun commentaire:
Enregistrer un commentaire