Go to file
jim teeuwen 8c492695c1 Changed slice code to use append() 2010-11-05 01:26:35 +01:00
xmlx Changed slice code to use append() 2010-11-05 01:26:35 +01:00
LICENSE Reworked README and xmlx/entitymap.go. Now includes conversion of named xml entities instead of just numeric ones. Eg: π and π to a unicode character and vice-versa. It also came to my attention that lack of a proper opensource license might put people off of using this package. I therefor added a 1-clause BSD license under which this code now falls. 2010-09-26 22:59:14 +02:00
README Reworked README and xmlx/entitymap.go. Now includes conversion of named xml entities instead of just numeric ones. Eg: π and π to a unicode character and vice-versa. It also came to my attention that lack of a proper opensource license might put people off of using this package. I therefor added a 1-clause BSD license under which this code now falls. 2010-09-26 22:59:14 +02:00
makefile Refactored some code to be faster and a little more elegant. 2010-08-22 05:07:38 +02:00

README

 Author: Jim Teeuwen <jimteeuwen@gmail.com>

 This package wraps the standard XML library and uses it to build a node tree of
 any document you load. This allows you to look up nodes forwards and backwards,
 as well as perform search queries (no xpath support).

 Nodes now simply become collections and don't require you to read them in the
 order in which the xml.Parser finds them.

================================================================================
 USAGE
================================================================================

 Getting the package up and running is simple enough:
 
 $ cd /path/to/code/dir
 $ git clone http://github.com/jteeuwen/go-pkg-xmlx.git
 $ cd go-pkg-xmlx
 $ make

================================================================================
 API
================================================================================

 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;
 
 SelectNode() returns the first, single node it finds matching the given name
 and namespace. SelectNodes() returns a slice containing all the matching nodes.
 
 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:
      <car>
        <color>red</color>
        <brand>BMW</brand>
      </car>

    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.

================================================================================
 LICENSE
================================================================================

This code is subject to a 1-clause BSD license.
It's contents can be found in the LICENSE file.