(r io.Reader)
| 9 | } |
| 10 | |
| 11 | func NewDocument(r io.Reader) (*Document, error) { |
| 12 | doc := &Document{ |
| 13 | Node: Node{ |
| 14 | // Attributes for document are always empty, but they are exposed, |
| 15 | // so we need to initialize them to avoid nil pointer dereference. |
| 16 | Attrs: NewAttributes(), |
| 17 | }, |
| 18 | } |
| 19 | |
| 20 | if err := doc.readFrom(r); err != nil { |
| 21 | return nil, err |
| 22 | } |
| 23 | |
| 24 | return doc, nil |
| 25 | } |
| 26 | |
| 27 | // ReplaceEntities replaces XML entities in the document |
| 28 | // according to the entity declarations in the DOCTYPE. |