私は、複数の石鹸レスポンスを解析するためのスクリプトを書くことを試みています。XMLファイルを1行ずつ読む
ここでは、解析しようとしているxmlのxmlスニペットのスニペットを示します。その完全なSOAPレスポンスが、私はちょうどタグ私は新しい行に各result
を印刷したい
<Results xsi:type="AccountUser">
<Client>
<ID>72rere341</ID>
</Client>
<PartnerKey xsi:nil="true" />
<PartnerProperties>
<Name>email</Name>
<Value>[email protected]</Value>
</PartnerProperties>
<ID>755454475</ID>
<ObjectID xsi:nil="true" />
<UserID>5fd0acfc-6crerfrgrfe6e9a675f65</UserID>
<ActiveFlag>true</ActiveFlag>
<Delete>0</Delete>
<LastSuccessfulLogin>2014-11-07T16:00:46.747</LastSuccessfulLogin>
</Results>
<Results xsi:type="AccountUser">
<Client>
<ID>72rere5341</ID>
</Client>
<PartnerKey xsi:nil="true" />
<PartnerProperties>
<Name>email</Name>
<Value>[email protected]</Value>
</PartnerProperties>
<ID>7225483</ID>
<ObjectID xsi:nil="true" />
<UserID>[email protected]</UserID>
<ActiveFlag>false</ActiveFlag>
<Delete>0</Delete>
<LastSuccessfulLogin>2015-04-29T05:01:27.85</LastSuccessfulLogin>
</Results>
を解析したいということが含まれています。ここで
は私のコードの抜粋です:私はターミナルでこれを実行すると
package main
import (
"os"
"fmt"
"encoding/xml"
"io/ioutil"
)
type AccountUser struct {
ParentMID string `xml:"Client>ID"`
EmailAddress string `xml:"PartnerProperties>Value"`
BuinessUnit string `xml:"ID"`
UserID string `xml:"UserID"`
Active string`xml:"ActiveFlag"`
LastSucessfulLogin string`xml:"LastSucessfulLogin"`
}
type Email struct {
Email string `xml:"PartnerProperties>Value"`
}
type Query struct {
Accounts AccountUser
AccountList []Email `xml:"PartnerProperties>Value"`
}
func (a AccountUser) String() string {
return fmt.Sprintf("%s - %s - %s", a.ParentMID, a.EmailAddress, a.UserID)
}
func main() {
xmlFile, err := os.Open("Results.xml")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer xmlFile.Close()
b, _ := ioutil.ReadAll(xmlFile)
var q Query
xml.Unmarshal(b, &q)
fmt.Println(q.Accounts)
for _, account := range q.AccountList {
fmt.Printf("\t%s\n", account)
}
}
、それは何も すなわちを返しません。
私はこれを解決する方法についての指針が大好きです。
@ Data_Kid、あなたが処理するXML文書内の重要でない空白(区切りのようなもの)について何も仮定してはいけないことに注意してください。それは、それらを生成するソフトウェアの更新や再構成のためにいつでも破損する可能性があります。 – kostix