1 回答

TA貢獻2080條經驗 獲得超4個贊
如果你想要:
xml 中的解析器
喜歡
xml:"n1:Level-1C_User_Product"
應該:
xml:"https://psd-14.sentinel2.eo.esa.int/PSD/User_Product_Level-1C.xsd Level-1C_User_Product"
請參閱:在 GO 中解析 Xml 以獲取標簽中帶有“:”的屬性
下面是一個演示:
package main
import (
"encoding/xml"
"fmt"
"os"
)
type L1CProduct struct {
XMLName xml.Name `xml:"https://psd-14.sentinel2.eo.esa.int/PSD/User_Product_Level-1C.xsd Level-1C_User_Product"`
N1GeneralInfo N1GeneralInfo
}
type N1GeneralInfo struct {
XMLName xml.Name `xml:"https://psd-14.sentinel2.eo.esa.int/PSD/User_Product_Level-1C.xsd General_Info"`
ProductInfo ProductInfo `xml:"Product_Info"`
}
type ProductInfo struct {
XMLName xml.Name `xml:"Product_Info"`
ProductStartTime string `xml:"PRODUCT_START_TIME"`
GenerationTime string `xml:"GENERATION_TIME"`
ProductUri string `xml:"PRODUCT_URI"`
}
func parseXml() {
// Open our xmlFile
// xmlPath := inProcessPath + "/MTD_MSIL1C.xml"
xmlPath := "./MTD_MSIL1C.xml"
// read our opened xmlFile as a byte array.
byteValue, _ := os.ReadFile(xmlPath)
// we initialize our Users array
var users L1CProduct
err := xml.Unmarshal(byteValue, &users)
if err != nil {
fmt.Printf("%v\n", err)
}
fmt.Println(users.N1GeneralInfo.ProductInfo.ProductStartTime + "o")
}
func main() {
parseXml()
}
以下是輸出:
2022-11-09T16:55:19.024Zo
- 1 回答
- 0 關注
- 175 瀏覽
添加回答
舉報