我要解析的 XML 数据是:<cm><id>TASK_DATA_RES</id><task> <swid>3873-0</swid> <detail> <![CDATA[<execute name="EXECUTE"> <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>https://mspnocsupport.com/downloadScript.doaction=downloadAgent&fileName=DiskStatusCheck.ps1&version=5.00</path> <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 文档的相应结构: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"` }之后我想打印详细结构的单个值,例如名称、Swid 等。
- 1 回答
- 0 关注
- 139 浏览
添加回答
举报
0/150
提交
取消