第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 Go 中解析多個(gè) XML 標(biāo)簽

在 Go 中解析多個(gè) XML 標(biāo)簽

Go
慕妹3146593 2021-11-15 20:34:40
我正在嘗試為 sslscan 解析一個(gè) xml 文件,它具有以下輸出(已縮短)。我想用 Go 解析它。<document title="SSLScan Results"> <ssltest host="x.x.x.x" port="443">   <cipher status="accepted" sslversion="TLSv1.0" bits="256" cipher="DHE-RSA-CAMELLIA256-SHA" dhebits="2048" />             .             .   <cipher status="accepted" sslversion="TLSv1.2" bits="112" cipher="DES-CBC3-SHA" />               .  <certificate>   <not-valid-before>Jun  6 00:00:00 2014 GMT</not-valid-before>   <not-valid-after>Jul  4 23:59:59 2017 GMT</not-valid-after>  </certificate> </ssltest></document>代碼:type XMLStrap struct {  Status     string `xml:"status,attr"`  SSLversion string `xml:"sslversion,attr"`  Bits       string `xml:"bits,attr"`  Cipher     string `xml:"cipher,attr"`}type XMLStraps struct {  XMLName xml.Name   `xml:"document"`  Straps  []XMLStrap `xml:"ssltest>cipher"`}func ReadStraps(reader io.Reader) ([]XMLStrap, error) {  var xmlStraps XMLStraps  if err := xml.NewDecoder(reader).Decode(&xmlStraps); err != nil {    return nil, err  }  return xmlStraps.Straps, nil}func main() {  strapsFilePath, err := filepath.Abs("straps.xml")  if err != nil {    fmt.Println(err)    os.Exit(1)  }  file, err := os.Open(strapsFilePath)  if err != nil {    fmt.Println(err)    os.Exit(1)  }  defer file.Close()  xmlStraps, err := ReadStraps(file)  if err != nil {    fmt.Println(err)    os.Exit(1)  }  for i := 0; i < len(xmlStraps); i++ {    fmt.Printf("%s %s %s %s\n", xmlStraps[i].Status,      xmlStraps[i].SSLversion, xmlStraps[i].Bits, xmlStraps[i].Cipher)  }}一切正常,但我不知道如何在<certificate><not-valid-before>不創(chuàng)建新閱讀器的情況下解析日期?我試圖將前兩個(gè)結(jié)構(gòu)更改為type XMLStrap struct {  Status     string `xml:"cipher>status,attr"`  SSLversion string `xml:"cipher>sslversion,attr"`  Bits       string `xml:"cipher>bits,attr"`  Cipher     string `xml:"cipher>cipher,attr"`  Cert       string `xml:"certificate>not-valid-after,chardata"`}type XMLStraps struct {  XMLName xml.Name   `xml:"document"`  Straps  []XMLStrap `xml:"ssltest"`}顯然在舊版本的 Go 中它有效。
查看完整描述

1 回答

?
呼如林

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊

我必須將新對(duì)象的參數(shù)分配給返回的對(duì)象。我以前試過這個(gè),但我犯了一個(gè)錯(cuò)誤


type XMLStrap struct {

  Status     string `xml:"status,attr"`

  SSLversion string `xml:"sslversion,attr"`

  Bits       string `xml:"bits,attr"`

  Cipher     string `xml:"cipher,attr"`

  Valid      string ""

}


type Certs struct {

  Cert string `xml:"not-valid-after"`

}


type XMLStraps struct {

  XMLName    xml.Name   `xml:"document"`

  Straps     []XMLStrap `xml:"ssltest>cipher"`

  Validation Certs      `xml:"ssltest>certificate"`

}


func ReadStraps(reader io.Reader) ([]XMLStrap, error) {

  var xmlStraps XMLStraps

  if err := xml.NewDecoder(reader).Decode(&xmlStraps); err != nil {

    return nil, err

  }

  xmlStraps.Straps[0].Valid = xmlStraps.Validation.Cert

  return xmlStraps.Straps, nil

}


查看完整回答
反對(duì) 回復(fù) 2021-11-15
  • 1 回答
  • 0 關(guān)注
  • 240 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)