Skip to content

Commit

Permalink
add support for first level of children tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crapooze committed May 4, 2013
1 parent bb02f65 commit 7850132
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/em-xmpp/xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ def match(elem, ns_mapping)
same_ns = elem.xmlns == wanted_ns

matching = same_value & same_ns
end

def find(elem, ns_mapping)
ret = []
ret << elem if matching
ret << elem if match(elem, ns_mapping)

case type
when 'normal'
#nothing
elem.children.each do |n|
ret << n if match(n, ns_mapping)
end
when 'relative', 'anywhere' #TODO: for anywhere, should go to the root first, is that even possible?
elem.children.each do |n|
match(n, ns_mapping).each {|m| ret << m}
find(n, ns_mapping).each {|m| ret << m}
end
else
raise NotImplementedError
Expand Down Expand Up @@ -59,11 +63,12 @@ def xpath(path,ns_mapping)
queries = parse_xpath(path)
elems = []
queries.each do |q|
q.match(self,ns_mapping).each do |n|
q.find(self,ns_mapping).each do |n|
elems << n
end
end
elems.uniq
ret = elems.uniq
ret
end

def children
Expand Down

0 comments on commit 7850132

Please sign in to comment.