MCPcopy Create free account
hub / github.com/antchfx/xpath / createMyBookExample

Function createMyBookExample

xpath_test.go:933–1001  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

931}
932
933func createMyBookExample() *TNode {
934 /*
935 <?xml version="1.0" encoding="utf-8"?>
936 <books xmlns:mybook="http://www.contoso.com/books">
937 <mybook:book id="bk101">
938 <title>XML Developer's Guide</title>
939 <author>Gambardella, Matthew</author>
940 <price>44.95</price>
941 <publish_date>2000-10-01</publish_date>
942 </mybook:book>
943 <mybook:book id="bk102">
944 <title>Midnight Rain</title>
945 <author>Ralls, Kim</author>
946 <price>5.95</price>
947 <publish_date>2000-12-16</publish_date>
948 </mybook:book>
949 </books>
950 */
951 var (
952 prefix string = "mybook"
953 namespaceURL string = "http://www.contoso.com/books"
954 )
955 lines := 1
956 doc := createNode("", RootNode)
957 doc.lines = lines
958 lines++
959 books := doc.createChildNode("books", ElementNode)
960 books.addAttribute("xmlns:mybook", namespaceURL)
961 books.lines = lines
962 lines++
963 data := []struct {
964 id string
965 title string
966 author string
967 price float64
968 publish string
969 }{
970 {id: "bk101", title: "XML Developer's Guide", author: "Gambardella, Matthew", price: 44.95, publish: "2000-10-01"},
971 {id: "bk102", title: "Midnight Rain", author: "Ralls, Kim", price: 5.95, publish: "2000-12-16"},
972 }
973 for i := 0; i < len(data); i++ {
974 v := data[i]
975 book := books.createChildNode("book", ElementNode)
976 book.addAttribute("id", v.id)
977 book.Prefix = prefix
978 book.NamespaceURL = namespaceURL
979 book.lines = lines
980 lines++
981 title := book.createChildNode("title", ElementNode)
982 title.createChildNode(v.title, TextNode)
983 title.lines = lines
984 lines++
985 author := book.createChildNode("author", ElementNode)
986 author.createChildNode(v.author, TextNode)
987 author.lines = lines
988 lines++
989 price := book.createChildNode("price", ElementNode)
990 price.createChildNode(fmt.Sprintf("%.2f", v.price), TextNode)

Callers 1

xpath_test.goFile · 0.85

Calls 3

createNodeFunction · 0.85
createChildNodeMethod · 0.80
addAttributeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…