Files
bl/common/data/xmlres/xml_test.go

144 lines
5.1 KiB
Go
Raw Normal View History

package xmlres
import (
"fmt"
"strings"
"testing"
"github.com/ECUST-XX/xml"
"github.com/antchfx/xmlquery"
)
var s = `
<?xml version="1.0" encoding="UTF-8" ?>
<!--
多个地图ID归属于一个星球
此XML表主要配置一些各个星球有可能需要用到的共用信息, 比如目前在世界地图上显示玩家所在位置
-->
<superMaps>
<maps id="1" name="传送舱" x="" y=""/>
<maps id="4" name="船长室" x="" y=""/>
<maps id="5" name="实验室" x="" y=""/>
<maps id="6" name="动力室" x="" y=""/>
<maps id="7" name="瞭望舱" x="" y=""/>
<maps id="8" name="机械室" x="" y=""/>
<maps id="9" name="资料室" x="" y=""/>
<maps id="19" name="太空站" x="" y=""/>
<maps id="101" name="教官办公室" x="" y=""/>
<maps id="103" name="瞭望露台" x="" y=""/>
<maps id="107" name="发明室" x="" y=""/>
<!--星球-->
<maps id="10 11 12 13" name="克洛斯星" galaxy="1" x="358" y="46"/>
<maps id="15 16 17" name="火山星" galaxy="1" x="533" y="46"/>
<maps id="20 21 22" name="海洋星" galaxy="1" x="190" y="11"/>
<maps id="25 26 27" name="云霄星" galaxy="1" x="652" y="24"/>
<maps id="30 31 32 33 34 35 36" name="赫尔卡星" galaxy="1" x="45" y="34"/>
<maps id="40 41 42 43" name="塞西利亚星" galaxy="1" x="1012" y="30"/>
<maps id="17" name="双子阿尔法星" galaxy="1" x="822" y="96"/>
<maps id="47 49" name="双子贝塔星" galaxy="1" x="883" y="63"/>
<maps id="51 52 53" name="斯诺星" galaxy="1" x="1290" y="15"/>
<maps id="54 55 56" name="露西欧星" galaxy="1" x="1405" y="120"/>
<maps id="57 58 59" name="尼古尔星" galaxy="2" x="30" y="50"/>
<maps id="60 61 62 63 64" name="塔克星" galaxy="2" x="135" y="44"/>
<maps id="325 326 327" name="艾迪星" galaxy="2" x="250" y="30"/>
<maps id="328" name="斯科尔星" galaxy="2" x="375" y="40"/>
<maps id="333 334" name="普雷空间站" galaxy="2" x="500" y="50"/>
<maps id="338 339" name="哈默星" galaxy="2" x="590" y="70"/>
<maps id="314" name="拜伦号" galaxy="1" x="1160" y="55"/>
</superMaps>`
func Test_main(t *testing.T) {
initfile()
fmt.Println(SkillMap[10073])
}
func main1() {
s := `
<?xml version="1.0" encoding="UTF-8" ?>
<!--
多个地图ID归属于一个星球
此XML表主要配置一些各个星球有可能需要用到的共用信息, 比如目前在世界地图上显示玩家所在位置
-->
<superMaps>
<maps id="1" name="传送舱" x="" y=""/>
<maps id="4" name="船长室" x="" y=""/>
<maps id="5" name="实验室" x="" y=""/>
<maps id="6" name="动力室" x="" y=""/>
<maps id="7" name="瞭望舱" x="" y=""/>
<maps id="8" name="机械室" x="" y=""/>
<maps id="9" name="资料室" x="" y=""/>
<maps id="19" name="太空站" x="" y=""/>
<maps id="101" name="教官办公室" x="" y=""/>
<maps id="103" name="瞭望露台" x="" y=""/>
<maps id="107" name="发明室" x="" y=""/>
<!--星球-->
<maps id="10 11 12 13" name="克洛斯星" galaxy="1" x="358" y="46"/>
<maps id="15 16 17" name="火山星" galaxy="1" x="533" y="46"/>
<maps id="20 21 22" name="海洋星" galaxy="1" x="190" y="11"/>
<maps id="25 26 27" name="云霄星" galaxy="1" x="652" y="24"/>
<maps id="30 31 32 33 34 35 36" name="赫尔卡星" galaxy="1" x="45" y="34"/>
<maps id="40 41 42 43" name="塞西利亚星" galaxy="1" x="1012" y="30"/>
<maps id="17" name="双子阿尔法星" galaxy="1" x="822" y="96"/>
<maps id="47 49" name="双子贝塔星" galaxy="1" x="883" y="63"/>
<maps id="51 52 53" name="斯诺星" galaxy="1" x="1290" y="15"/>
<maps id="54 55 56" name="露西欧星" galaxy="1" x="1405" y="120"/>
<maps id="57 58 59" name="尼古尔星" galaxy="2" x="30" y="50"/>
<maps id="60 61 62 63 64" name="塔克星" galaxy="2" x="135" y="44"/>
<maps id="325 326 327" name="艾迪星" galaxy="2" x="250" y="30"/>
<maps id="328" name="斯科尔星" galaxy="2" x="375" y="40"/>
<maps id="333 334" name="普雷空间站" galaxy="2" x="500" y="50"/>
<maps id="338 339" name="哈默星" galaxy="2" x="590" y="70"/>
<maps id="314" name="拜伦号" galaxy="1" x="1160" y="55"/>
</superMaps>`
doc, err := xmlquery.Parse(strings.NewReader(s))
if err != nil {
panic(err)
}
//channel := xmlquery.FindOne(doc, "//superMaps")
// if n := channel.SelectElement("maps"); n != nil {
// fmt.Printf("title: %s\n", n.InnerText())
// }
if l := xmlquery.Find(doc, "//maps[@id='9']"); l != nil {
t := l[0].Attr
fmt.Printf("%v", t[1])
}
// for i, n := range xmlquery.Find(doc, "//maps/@id") {
// fmt.Printf("#%d %s\n", i, n.InnerText())
// }
}
func TestMMMs(t *testing.T) {
decoder := xml.NewDecoder(strings.NewReader(s))
var rootComments []string
rootFound := false
for {
token, err := decoder.Token()
if err != nil {
break
}
switch t := token.(type) {
case xml.StartElement:
// 遇到根元素开始标签后停止收集注释
rootFound = true
fmt.Printf("找到根元素: %s\n", t.Name.Local)
case xml.Comment:
if !rootFound {
// 保存根元素前的注释
rootComments = append(rootComments, string(t))
}
}
}
// 输出捕获的根注释
fmt.Println("\n根注释内容:")
for _, comment := range rootComments {
fmt.Println(strings.TrimSpace(comment))
}
}