From dcae3f9bff1fde63b6b80710787317cea89244d3 Mon Sep 17 00:00:00 2001 From: jim teeuwen Date: Tue, 24 Nov 2009 14:50:37 +0100 Subject: [PATCH] rewrote README with better information --- README | 65 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/README b/README index 13ac910..659d701 100644 --- a/README +++ b/README @@ -8,27 +8,11 @@ Nodes now simply become collections and don't require you to read them in the order in which the xml.Parser finds them. - xmlx.Document implements both these interfaces: - - type ILoader interface { - LoadFile(string) os.Error; - LoadString(string) os.Error; - LoadStream(*io.Reader) os.Error; - } - - type ISaver interface { - SaveFile(string) os.Error; - SaveString(string) (string, os.Error); - SaveStream(*io.Writer) os.Error; - } - - This allows you to load/save xml data to and from pretty much any source. - The Document currently implements 2 simple search functions which allow you to look for specific nodes. - Document.SelectNode(namespace, name string) *Node; - Document.SelectNodes(namespace, name string) []*Node; + *document.SelectNode(namespace, name string) *Node; + *document.SelectNodes(namespace, name string) []*Node; SelectNode() returns the first, single node it finds matching the given name and namespace. SelectNodes() returns a slice containing all the matching nodes. @@ -36,3 +20,48 @@ Note that these search functions can be invoked on individual nodes as well. This allows you to search only a subset of the entire document. + Each node exposes also a number of functions which allow easy access to a node + value or an attribute value. They come in various forms to allow transparent + conversion to types like int, int64, float, float32, float64, etc: + + *node.GetValue(ns, name string) string; + *node.GetValuei(ns, name string) int; + *node.GetValuei64(ns, name string) int64; + *node.GetValuef(ns, name string) float; + *node.GetValuef32(ns, name string) float32; + *node.GetValuef64(ns, name string) float64; + + Note that the GetValue() functions actually consider child nodes for matching + names as well as the current node. In effect they first perform a + node.SelectNode() and then return the value of the resulting node converted to + the appripriate type. This allows you to do this: + + Consider this piece of xml: + + red + BMW + + + Now this code: + node := doc.SelectNode("", "car"); + brand := node.GetValue("", "brand"); + + Eventhough 'brand' is not the name of @node, we still get the right value + back (BMW), because GetValue searches through the child nodes when looking + for the value if the current node does not match the given namespace and + name. + + For attributes, we only go through the attributes of the current node this + function is invoked on: + + *node.GetAttr(ns, name string) string; + *node.GetAttri(ns, name string) int; + *node.GetAttri64(ns, name string) int64; + *node.GetAttrf(ns, name string) float; + *node.GetAttrf32(ns, name string) float32; + *node.GetAttrf64(ns, name string) float64; + + All of these functions return either "" or 0 when the specified node or + attribute could not be found. No errors are generated. + +