Esempio n. 1
0
func (e *XMLConnector) commit() {
	e.db.Seek(0, 0)
	e.db.Truncate(0)
	fmt.Fprintln(e.db, "<?xml version=\"1.0\" ?>")
	fmt.Fprintln(e.db, "<db>")
	fmt.Fprintln(e.db, "<schema>")
	for table, tabledesc := range e.tables {
		//		fmt.Println("Comitting table " + table + " struct " + fmt.Sprint(tabledesc))
		fmt.Fprintf(e.db, "<table name=\"%s\">\n", table)
		for key, typ := range tabledesc.Attributes() {
			fmt.Fprintf(e.db, "<attribute type=\"%s\">%s</attribute>\n", typeName(typ), key)
		}
		fmt.Fprintln(e.db, "</table>")
	}
	fmt.Fprintln(e.db, "</schema>")
	fmt.Fprintln(e.db, "<data>")
	for table, tabledesc := range e.tables {
		fmt.Fprintf(e.db, "<tabledata name=\"%s\">\n", table)
		for i := 0; i < tabledesc.Data().Len(); i++ {
			values := tabledesc.Data().At(i).(map[string]Value)
			fmt.Fprintln(e.db, "<item>")

			for key, typ := range tabledesc.Attributes() {
				fmt.Fprintf(e.db, "<value name=\"%s\">", key)
				switch typ {
				case IntKind:
					fmt.Fprintf(e.db, "%d", int(values[key].Int()))
				case StringKind:
					xml.Escape(e.db, bytes.NewBufferString(string(values[key].String())).Bytes())
				}
				fmt.Fprintf(e.db, "</value>\n")
			}

			fmt.Fprintln(e.db, "</item>")
		}
		fmt.Fprintln(e.db, "</tabledata>")
	}
	fmt.Fprintln(e.db, "</data>")
	fmt.Fprint(e.db, "</db>")
}
Esempio n. 2
0
File: svg.go Progetto: krasin/svgo
// tt creates a xml element, tag containing s
func (svg *SVG) tt(tag string, s string) {
	svg.print("<" + tag + ">")
	xml.Escape(svg.Writer, []byte(s))
	svg.println("</" + tag + ">")
}
Esempio n. 3
0
File: svg.go Progetto: krasin/svgo
// Textpath places text optionally styled text along a previously defined path
// Standard Reference: http://www.w3.org/TR/SVG11/text.html#TextPathElement
func (svg *SVG) Textpath(t string, pathid string, s ...string) {
	svg.printf("<text %s<textPath xlink:href=\"%s\">", endstyle(s, ">"), pathid)
	xml.Escape(svg.Writer, []byte(t))
	svg.println(`</textPath></text>`)
}
Esempio n. 4
0
File: svg.go Progetto: krasin/svgo
// Text places the specified text, t at x,y according to the style specified in s
// Standard Reference: http://www.w3.org/TR/SVG11/text.html#TextElement
func (svg *SVG) Text(x int, y int, t string, s ...string) {
	svg.printf("<text %s %s", loc(x, y), endstyle(s, ">"))
	xml.Escape(svg.Writer, []byte(t))
	svg.println(`</text>`)
}
Esempio n. 5
0
File: svg.go Progetto: krasin/svgo
// Link begins a link named "name", with the specified title.
// Standard Reference: http://www.w3.org/TR/SVG11/linking.html#Links
func (svg *SVG) Link(href string, title string) {
	svg.printf("<a xlink:href=\"%s\" xlink:title=\"", href)
	xml.Escape(svg.Writer, []byte(title))
	svg.println("\">")
}
Esempio n. 6
0
File: svg.go Progetto: krasin/svgo
// Gid begins a group, with the specified id
func (svg *SVG) Gid(s string) {
	svg.print(`<g id="`)
	xml.Escape(svg.Writer, []byte(s))
	svg.println(`">`)
}
Esempio n. 7
0
func escape(w io.Writer, str string) {
	xml.Escape(w, []uint8(str))
}