Go to file
jim teeuwen c07619da34 Fixed potential case issue in correctEncoding(). As per issue#2. 2011-01-30 23:19:52 +01:00
LICENSE Fix issue 1: Added dependency to go-iconv. this lib is needed to ensure we pass valud UTF-8 encoded data to the XML tokenizer. 2011-01-18 21:31:56 +01:00
Makefile Making package easily usable with goinstall. Including the reference to go-iconv. 2011-01-20 22:48:03 +01:00
README Fix bug in document.correctEncoding() which failed to properly parse xml doctypes. 2011-01-27 22:10:38 +01:00
document.go Fixed potential case issue in correctEncoding(). As per issue#2. 2011-01-30 23:19:52 +01:00
entitymap.go Making package easily usable with goinstall. Including the reference to go-iconv. 2011-01-20 22:48:03 +01:00
node.go Making package easily usable with goinstall. Including the reference to go-iconv. 2011-01-20 22:48:03 +01:00
test.xml Making package easily usable with goinstall. Including the reference to go-iconv. 2011-01-20 22:48:03 +01:00
xmlx_test.go Fix bug in document.correctEncoding() which failed to properly parse xml doctypes. 2011-01-27 22:10:38 +01:00

README

 Author: Jim Teeuwen <jimteeuwen at 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.

================================================================================
 DEPENDENCIES
================================================================================

 goinstall github.com/sloonz/go-iconv/src

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

 Getting the package up and running is simple enough:
 
    $ goinstall github.com/jteeuwen/go-pkg-xmlx

 Using it:

    import xmlx "github.com/jteeuwen/go-pkg-xmlx"

================================================================================
 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: int, int64, uint, uint64, float, float32, float64:

   *node.S(ns, name string) string
   *node.I(ns, name string) int
   *node.I64(ns, name string) int64
   *node.U(ns, name string) uint
   *node.U64(ns, name string) uint64
   *node.F(ns, name string) float
   *node.F32(ns, name string) float32
   *node.F64(ns, name string) float64
   *node.B(namespace, name string) bool

 Note that these 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 appropriate 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.S("", "brand")

    Eventhough 'brand' is not the name of @node, we still get the right value
    back (BMW), because node.S() 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.As(ns, name string) string
   *node.Ai(ns, name string) int
   *node.Ai64(ns, name string) int64
   *node.Au(ns, name string) uint
   *node.Au64(ns, name string) uint64
   *node.Af(ns, name string) float
   *node.Af32(ns, name string) float32
   *node.Af64(ns, name string) float64
   *node.Ab(namespace, name string) bool

 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.