Help with parsing xml data


(Kevin Hoyt) #1

I’m trying to parse some xml data that I’m getting from an api query and I’m having trouble. Here are the structs I’ve laid out and the xml data itself. Any help would be appreciated.

‘’’
type ListTraceResponse struct {
ListTraceCompRows []ListTraceCompRow xml:"<?xml version=\"1.0\" encoding=\"utf-8\"?><dp:ListTraceComponentsReply ReturnCode=\"0\" xmlns:dp=\"http://www.cisco.com/vtg/diagnosticportal\"><dp:Schema Version=\"1.0\" />"
}

type ListTraceCompRow struct {
Name string xml:"<dp:TraceComponent Name"
TraceCompList []CompList xml:"dp:TraceComponentList"

}

type CompList struct {
Name string xml:"TraceComponent Name"
Description string xml:"Description"
}

<?xml version="1.0" encoding="utf-8"?>

‘’’

Thanks,
Kevin


(Kevin Hoyt) #2

the xml didn’t pate properly, here’s the data:

‘’’<?xml version="1.0" encoding="utf-8"?><dp:ListTraceComponentsReply ReturnCode=“0” xmlns:dp=“http://www.cisco.com/vtg/diagnosticportal”><dp:Schema Version=“1.0” />dp:TraceComponentList<dp:TraceComponent Name=“Logger A” ComponentType=“Logger” Description=“ICM Component” IsLevelConfigurable=“true” IsFileCollectable=“true”>dp:TraceComponentList<dp:TraceComponent Name=“baImport” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“CampaignManager” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“clgr” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“csfs” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“cw2kFeed” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“dtp” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“hlgr” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“nm” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“nmm” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“rcv” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“rpl” Description=“ICM process for component: LoggerA” IsLevelConfigurable=“true” IsFileCollectable=“true” /></dp:TraceComponentList></dp:TraceComponent><dp:TraceComponent Name=“Router A” ComponentType=“Router” Description=“ICM Component” IsLevelConfigurable=“true” IsFileCollectable=“true”>dp:TraceComponentList<dp:TraceComponent Name=“agi” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“ccag” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“csn” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“dba” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“dbw” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“mds” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“nm” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“nmm” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“nms” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“rtr” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“rts” Description=“ICM process for component: RouterA” IsLevelConfigurable=“true” IsFileCollectable=“true” /></dp:TraceComponentList></dp:TraceComponent><dp:TraceComponent Name=“Cisco ICM Diagnostic Framework” Description=“Cisco ICM Diagnostic Framework” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“Web Setup” Description=“Web Setup” IsLevelConfigurable=“true” IsFileCollectable=“true” /><dp:TraceComponent Name=“Sadlib” Description=“Sadlib” IsLevelConfigurable=“true” IsFileCollectable=“true” /></dp:TraceComponentList></dp:ListTraceComponentsReply>
‘’’


( Kvaz1r) #3

You can use special tools for that. For example zek - Generate a Go struct from XML.


(Kevin Hoyt) #4

ahh, hadn’t seen a tool for xml, that worked. thanks!