Create an etree Document, add XML entities to it, and serialize it to stdout.
()
| 9 | // Create an etree Document, add XML entities to it, and serialize it |
| 10 | // to stdout. |
| 11 | func ExampleDocument_creating() { |
| 12 | doc := NewDocument() |
| 13 | doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`) |
| 14 | doc.CreateProcInst("xml-stylesheet", `type="text/xsl" href="style.xsl"`) |
| 15 | |
| 16 | people := doc.CreateElement("People") |
| 17 | people.CreateComment("These are all known people") |
| 18 | |
| 19 | jon := people.CreateElement("Person") |
| 20 | jon.CreateAttr("name", "Jon O'Reilly") |
| 21 | |
| 22 | sally := people.CreateElement("Person") |
| 23 | sally.CreateAttr("name", "Sally") |
| 24 | |
| 25 | doc.Indent(2) |
| 26 | doc.WriteTo(os.Stdout) |
| 27 | // Output: |
| 28 | // <?xml version="1.0" encoding="UTF-8"?> |
| 29 | // <?xml-stylesheet type="text/xsl" href="style.xsl"?> |
| 30 | // <People> |
| 31 | // <!--These are all known people--> |
| 32 | // <Person name="Jon O'Reilly"/> |
| 33 | // <Person name="Sally"/> |
| 34 | // </People> |
| 35 | } |
| 36 | |
| 37 | func ExampleDocument_reading() { |
| 38 | doc := NewDocument() |
nothing calls this directly
no test coverage detected