feat(命名空间): 规范声明顺序,修复命名空间
build.yaml / build (push) Successful in 49s

This commit is contained in:
xiaoqidun committed 2026-10-12 11:20:30 +08:00
1 parent 17a9a03361
commit c4b81155a9
19 files changed
+410 -142

No files matched your search

+45 -18
View File
@@ -14,7 +14,10 @@
package ofdgo
import "encoding/xml"
import (
"encoding/xml"
"fmt"
)
// ofdCreator 标识本库生成的文档
const ofdCreator = "xiaoqidun/ofdgo"
@@ -37,23 +40,6 @@ type DocBody struct {
versioned bool
}
// UnmarshalXML 读取文档入口并记录版本列表是否存在,版本描述在选择时读取
// 入参: decoder XML解码器, start 起始节点
// 返回: error 解析错误
func (body *DocBody) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error {
type docBody DocBody
var value struct {
docBody
Versions *struct{} `xml:"Versions"`
}
if err := decoder.DecodeElement(&value, &start); err != nil {
return err
}
*body = DocBody(value.docBody)
body.versioned = value.Versions != nil
return nil
}
// DocInfo 文档元数据
type DocInfo struct {
DocID string `xml:"DocID"`
@@ -79,3 +65,44 @@ type CustomData struct {
Value string `xml:",chardata"`
sourceIndex int
}
// UnmarshalXML 读取主入口,区分标准文档条目与扩展中的同名节点
// 入参: decoder XML解码器, start 起始节点
// 返回: error 解析错误
func (ofd *OFD) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error {
if start.Name.Local != "OFD" {
return fmt.Errorf("expected OFD root, got %s", start.Name.Local)
}
*ofd = OFD{XMLName: start.Name, Version: attrValue(start, "Version"), DocType: attrValue(start, "DocType")}
return decodeOFDChildren(decoder, start, func(d *xml.Decoder, node xml.StartElement) error {
if node.Name.Local != "DocBody" {
return d.Skip()
}
var body DocBody
if err := d.DecodeElement(&body, &node); err != nil {
return err
}
ofd.DocBody = append(ofd.DocBody, body)
return nil
})
}
// UnmarshalXML 读取文档入口并记录版本列表是否存在,版本描述在选择时读取
// 入参: decoder XML解码器, start 起始节点
// 返回: error 解析错误
func (body *DocBody) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error {
*body = DocBody{}
return decodeOFDChildren(decoder, start, func(d *xml.Decoder, node xml.StartElement) error {
switch node.Name.Local {
case "DocInfo":
return d.DecodeElement(&body.DocInfo, &node)
case "DocRoot":
return d.DecodeElement(&body.DocRoot, &node)
case "Signatures":
return d.DecodeElement(&body.Signatures, &node)
case "Versions":
body.versioned = true
}
return d.Skip()
})
}