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

Function ExamplePath

example_test.go:44–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42}
43
44func ExamplePath() {
45 xml := `
46<bookstore>
47 <book>
48 <title>Great Expectations</title>
49 <author>Charles Dickens</author>
50 </book>
51 <book>
52 <title>Ulysses</title>
53 <author>James Joyce</author>
54 </book>
55</bookstore>`
56
57 doc := NewDocument()
58 doc.ReadFromString(xml)
59 for _, e := range doc.FindElements(".//book[author='Charles Dickens']") {
60 doc := NewDocumentWithRoot(e.Copy())
61 doc.Indent(2)
62 doc.WriteTo(os.Stdout)
63 }
64 // Output:
65 // <book>
66 // <title>Great Expectations</title>
67 // <author>Charles Dickens</author>
68 // </book>
69}

Callers

nothing calls this directly

Calls 7

NewDocumentFunction · 0.85
NewDocumentWithRootFunction · 0.85
ReadFromStringMethod · 0.80
FindElementsMethod · 0.80
IndentMethod · 0.80
WriteToMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected