0

私はxml出力からデータを抽出することに取り組んでいます。以下のコードを書きました。以下のxmlからdept番号を抽出するだけです。以下のコードを実行すると、null 出力が得られます。xml から dept 番号を抽出する方法と、出力として null を取得する理由を誰か教えてもらえますか?

package main

import (
    "encoding/xml"
    "fmt"
)

type Users struct {
    XMLName xml.Name `xml:"users"`
    User   User   `xml:"user"`
}
type User struct {
    XMLName xml.Name `xml:"user"` 
    Type string  `xml:"name"` 
    DD  DD   `xml:"dd"`
}
type DD struct {
    XMLName xml.Name `xml:"dd"` 
    Number string  `xml:"number"`
    Description string  `xml:"description"` 
   Type  Type   `xml:"type"`
    Dept  Dept   `xml:"dept"`
}
type Type struct{
   XMLName xml.Name `xml:"type"` 
}
type Dept struct {
    XMLName xml.Name `xml:"dept"`
    Number string  `xml:"number"`
   Type  Type   `xml:"type"`
}

func main() {
var users Users
var byteValue = []byte(`<users>
<user>
<type>1</type>
<bu>
    <number>123</number>
    <id>100</id>
    <type>
        <code>123</code>
    </type>
</bu>
<dd>
    <number>1</number>
    <description>abc</description>
    <type>
        <code>12345</code>
        <id>qw123<id>
    <type>
    <dept>
        <number>10</number>      <<<<<<<
        <type>qw12345</type>
        
    </dept>
</dd>
<bd>
    <code>34we5</code>
    <id>qw123<id>
</bd>
<OD>
    <code>9876</code>
    <id>qwerty123<id>
</OD>   
</user>
</users>`)
xml.Unmarshal(byteValue, &users)
fmt.Println("Dept Number: " + users.User.DD.Dept.Number)
}
4

1 に答える 1