etree
etree copied to clipboard
Add doctype read
Hello, how to read doctype in xml file ?
For example :
<!DOCTYPE article PUBLIC "my doctype of doom" "mydoctype.dtd">
<xpath>
<to>
<my>
<infos>trezaq</infos>
</my>
</to>
</xpath>
Hello, here my proposal:
package main
import (
"fmt"
"github.com/beevik/etree"
)
func main() {
xml := `<!DOCTYPE article PUBLIC "my doctype of doom" "mydoctype.dtd">
<xpath>
<to>
<my>
<infos>trezaq</infos>
</my>
</to>
</xpath>`
doc := etree.NewDocument()
if err := doc.ReadFromString(xml); err != nil {
panic(err)
}
children := doc.Child
for _, child := range children {
if dt, ok := child.(*etree.Directive); ok {
fmt.Print(dt.Data)
}
}
}