diff --git a/README b/README
index 02c22db..01a3da5 100644
--- a/README
+++ b/README
@@ -96,5 +96,7 @@
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.
+ 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/node.go b/node.go
index 2b6efe1..c69742b 100644
--- a/node.go
+++ b/node.go
@@ -196,10 +196,15 @@ func (this *Node) Ab(namespace, name string) bool {
// Returns true if this node has the specified attribute. False otherwise.
func (this *Node) HasAttr(namespace, name string) bool {
for _, v := range this.Attributes {
- if (namespace == "*" || namespace == v.Name.Space) && name == v.Name.Local {
+ if namespace != "*" && namespace != v.Name.Space {
+ continue
+ }
+
+ if name == "*" || name == v.Name.Local {
return true
}
}
+
return false
}
@@ -209,9 +214,7 @@ func (this *Node) SelectNode(namespace, name string) *Node {
}
func rec_SelectNode(cn *Node, namespace, name string) *Node {
- // Allow wildcard for namespace names. Meaning we will match any namespace
- // name with a matching local name.
- if (namespace == "*" || cn.Name.Space == namespace) && cn.Name.Local == name {
+ if (namespace == "*" || cn.Name.Space == namespace) && (name == "*" || cn.Name.Local == name) {
return cn
}
@@ -221,6 +224,7 @@ func rec_SelectNode(cn *Node, namespace, name string) *Node {
return tn
}
}
+
return nil
}
@@ -232,9 +236,7 @@ func (this *Node) SelectNodes(namespace, name string) []*Node {
}
func rec_SelectNodes(cn *Node, namespace, name string, list *[]*Node) {
- // Allow wildcard for namespace names. Meaning we will match any namespace
- // name with a matching local name.
- if (namespace == "*" || cn.Name.Space == namespace) && cn.Name.Local == name {
+ if (namespace == "*" || cn.Name.Space == namespace) && (name == "*" || cn.Name.Local == name) {
*list = append(*list, cn)
return
}
diff --git a/test1.xml b/test1.xml
deleted file mode 100644
index db44efa..0000000
--- a/test1.xml
+++ /dev/null
@@ -1 +0,0 @@
-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
diff --git a/test2.xml b/test2.xml
new file mode 100644
index 0000000..d488157
--- /dev/null
+++ b/test2.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ moo
+ 123
+ 321
+ 1/1/2011
+
+
+ moo
+ 123
+ 321
+ 1/1/2011
+
+
+
diff --git a/xmlx_test.go b/xmlx_test.go
index 21538c5..fb2bc82 100644
--- a/xmlx_test.go
+++ b/xmlx_test.go
@@ -20,7 +20,23 @@ func TestLoadLocal(t *testing.T) {
}
}
-func TestLoadRemote(t *testing.T) {
+func TestWildcard(t *testing.T) {
+ doc := New()
+
+ if err := doc.LoadFile("test2.xml"); err != nil {
+ t.Error(err.String())
+ return
+ }
+
+ list := doc.SelectNodes("xdc", "*")
+
+ if len(list) != 8 {
+ t.Errorf("Wrong number of child elements. Expected 4, got %d.", len(list))
+ return
+ }
+}
+
+func _TestLoadRemote(t *testing.T) {
doc := New()
if err := doc.LoadUri("http://blog.golang.org/feeds/posts/default"); err != nil {