MCPcopy Create free account
hub / github.com/beevik/etree / ExampleDocument_creating

Function ExampleDocument_creating

example_test.go:11–35  ·  view source on GitHub ↗

Create an etree Document, add XML entities to it, and serialize it to stdout.

()

Source from the content-addressed store, hash-verified

9// Create an etree Document, add XML entities to it, and serialize it
10// to stdout.
11func 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&apos;Reilly"/>
33 // <Person name="Sally"/>
34 // </People>
35}
36
37func ExampleDocument_reading() {
38 doc := NewDocument()

Callers

nothing calls this directly

Calls 7

IndentMethod · 0.95
WriteToMethod · 0.95
NewDocumentFunction · 0.85
CreateProcInstMethod · 0.80
CreateElementMethod · 0.80
CreateCommentMethod · 0.80
CreateAttrMethod · 0.80

Tested by

no test coverage detected