Skip to content

Commit 2aefc61

Browse files
committed
发布1.2.0版本,增强一点小功能
1 parent 0d38243 commit 2aefc61

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,10 @@ golang的xml解析器自身还不支持BOM,所以本解析器还无法解析
278278
- github仓库增加了构建服务,文档服务
279279
- 补充用例,增加代码覆盖率到90%以上
280280

281+
#### 1.2.0 小版本改进,能力增强,bug解决
282+
283+
- 只是直接指定文件名加载文档或者保存文档:因为这两种场景也比较常见,比较实用
284+
- 发现1.1.0版本新增函数引入的bug,可能导致对象被切片
285+
- 将两个全局量PreetyPrint改名为Print在前:因为发现Print在前更容易记忆
286+
- 完善文档
281287

tinydom.go

+30-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"unicode/utf8"
1010
"container/list"
11+
"os"
1112
)
1213

1314
// XMLAttribute 是一个元素的属性的接口.
@@ -883,6 +884,34 @@ func LoadDocument(rd io.Reader) (XMLDocument, error) {
883884
return nil, err
884885
}
885886

887+
func LoadDocumentFromFile(name string) (XMLDocument, error) {
888+
file, err := os.Open(name)
889+
if nil != err {
890+
return nil, err
891+
}
892+
defer file.Close()
893+
894+
return LoadDocument(file)
895+
}
896+
897+
// SaveDocumentToFile Print the xml-dom objects to the writer.
898+
func SaveDocument(doc XMLDocument, writer io.Writer, options PrintOptions) error {
899+
doc.Accept(NewSimplePrinter(writer, options))
900+
return nil
901+
}
902+
903+
// SaveDocumentToFile Print the xml-dom objects to the file.
904+
func SaveDocumentToFile(doc XMLDocument, name string, options PrintOptions) error {
905+
file, err := os.Create(name)
906+
if nil != err {
907+
return err
908+
}
909+
defer file.Close()
910+
911+
doc.Accept(NewSimplePrinter(file, options))
912+
return nil
913+
}
914+
886915
// DefaultVisitor 这个类的目的是简化编写定制扫描的visitor,使得我们不需要定制XMLVisitor的所有接口
887916
type DefaultVisitor struct {
888917
EnterDocument func(XMLDocument) bool
@@ -1345,5 +1374,5 @@ func EscapeText(w io.Writer, s []byte) error {
13451374

13461375
// Version 查询版本信息
13471376
func Version() string {
1348-
return "1.1.0"
1377+
return "1.2.0"
13491378
}

version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0
1+
1.2.0

0 commit comments

Comments
 (0)