From 45769307c0a03de4af3d4648b4ffda6a9b3a1c09 Mon Sep 17 00:00:00 2001 From: jim teeuwen Date: Tue, 20 Mar 2012 02:27:54 +0100 Subject: [PATCH] Rename README to README.md and fix contents. --- README | 89 ------------------------------------------------------- README.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test1.xml | 1 + 3 files changed, 90 insertions(+), 89 deletions(-) delete mode 100644 README create mode 100644 README.md create mode 100644 test1.xml diff --git a/README b/README deleted file mode 100644 index b3f9b6a..0000000 --- a/README +++ /dev/null @@ -1,89 +0,0 @@ - - Author: Jim Teeuwen - - 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 -================================================================================ - - none - -================================================================================ - 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: - - red - BMW - - - 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. - - The namespace name specified in the functions above must either match the - namespace you expect a node/attr to have, or you can specify a wildcard "*". - This makes node searches easier in case you do not care what namespace name - there is or if there is one at all. Node and attribute names as well, may - be supplied as the wildcard "*". This allows us to fetch all child nodes for - a given namespace, regardless of their names. - diff --git a/README.md b/README.md new file mode 100644 index 0000000..62758b7 --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +## XMLX + +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 + +None. + +### 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, 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.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: + + + red + BMW + + +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.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. + +The namespace name specified in the functions above must either match the +namespace you expect a node/attr to have, or you can specify a wildcard "*". +This makes node searches easier in case you do not care what namespace name +there is or if there is one at all. Node and attribute names as well, may +be supplied as the wildcard "*". This allows us to fetch all child nodes for +a given namespace, regardless of their names. + +### License + +This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication +license. Its contents can be found in the LICENSE file. + diff --git a/test1.xml b/test1.xml new file mode 100644 index 0000000..db44efa --- /dev/null +++ b/test1.xml @@ -0,0 +1 @@ +WriteTheWebhttp://writetheweb.comNews for web users that write backen-usCopyright 2000, WriteTheWeb team.editor@writetheweb.comwebmaster@writetheweb.comWriteTheWebhttp://writetheweb.com/images/mynetscape88.gifhttp://writetheweb.com8831News for web users that write backGiving the world a pluggable Gnutellahttp://writetheweb.com/read.php?item=24WorldOS is a framework on which to build programs that work like Freenet or Gnutella -allowing distributed applications using peer-to-peer routing.Syndication discussions hot uphttp://writetheweb.com/read.php?item=23After a period of dormancy, the Syndication mailing list has become active again, with contributions from leaders in traditional media and Web syndication.Personal web server integrates file sharing and messaginghttp://writetheweb.com/read.php?item=22The Magi Project is an innovative project to create a combined personal web server and messaging system that enables the sharing and synchronization of information across desktop, laptop and palmtop devices.Syndication and Metadatahttp://writetheweb.com/read.php?item=21RSS is probably the best known metadata format around. RDF is probably one of the least understood. In this essay, published on my O'Reilly Network weblog, I argue that the next generation of RSS should be based on RDF.UK bloggers get organisedhttp://writetheweb.com/read.php?item=20Looks like the weblogs scene is gathering pace beyond the shores of the US. There's now a UK-specific page on weblogs.com, and a mailing list at egroups.Yournamehere.com more important than anythinghttp://writetheweb.com/read.php?item=19Whatever you're publishing on the web, your site name is the most valuable asset you have, according to Carl Steadman. \ No newline at end of file