WriteTo writes the XML representation of the node and its children to the provided writer.
(w TokenWriter)
| 52 | |
| 53 | // WriteTo writes the XML representation of the node and its children to the provided writer. |
| 54 | func (n *Node) WriteTo(w TokenWriter) error { |
| 55 | if len(n.Name) == 0 { |
| 56 | // Document node or an unnamed node, write only children |
| 57 | return n.writeChildrenTo(w) |
| 58 | } |
| 59 | |
| 60 | selfClosing := len(n.Children) == 0 |
| 61 | |
| 62 | se := StartElement{ |
| 63 | Name: n.Name, |
| 64 | Attrs: n.Attrs, |
| 65 | SelfClosing: selfClosing, |
| 66 | } |
| 67 | |
| 68 | if err := se.WriteTo(w); err != nil { |
| 69 | return err |
| 70 | } |
| 71 | |
| 72 | if selfClosing { |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | if err := n.writeChildrenTo(w); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | |
| 80 | ee := EndElement{ |
| 81 | Name: n.Name, |
| 82 | } |
| 83 | |
| 84 | if err := ee.WriteTo(w); err != nil { |
| 85 | return err |
| 86 | } |
| 87 | |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | // readFrom reads XML data from the provided reader |
| 92 | // and populates the node and its children accordingly. |
nothing calls this directly
no test coverage detected