12.7-12.12

This commit is contained in:
Unknwon
2015-11-18 19:06:39 -05:00
parent 145cb40146
commit 48d5b9db25
10 changed files with 33 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
# 12.10 XML 数据格式
下面是与 12.9 节 JSON 例子等价的 XML 版本:
```xml
<Person>
<FirstName>Laura</FirstName>
@@ -56,8 +57,11 @@ func main() {
}
}
}
```
/* Output:
输出:
```
Token name: Person
Token name: FirstName
This is the content: Laura
@@ -66,9 +70,8 @@ Token name: LastName
This is the content: Lynn
End of token
End of token
*/
```
包中定义了若干 XML 标签类型StartElementChardata这是从开始标签到结束标签之间的实际文本EndElementCommentDirective 或 ProcInst。
包中同样定义了一个结构解析器:`NewParser` 方法持有一个 io.Reader这里具体类型是 strings.NewReader并生成一个解析器类型的对象。还有一个 `Token()` 方法返回输入流里的下一个 XML token。在输入流的结尾处会返回nilio.EOF