<< Back to previous view

[DZIP-6] Sub Entries with the same Name can't be selected Created: 19/Sep/16  Updated: 20/Sep/16

Status: Open
Project: data.zip
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Benjamin Peter Assignee: Alex Miller
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Leiningen 2.7.0 on Java 1.8.0_91 Java HotSpot(TM) 64-Bit Server VM


Attachments: File zip-xml-bug-descent.tgz     File zip-xml-bug.tgz    

 Description   

I want to select the content of an XML element named "Group" which itself is in an element named "Group" using xml-zip/xml1. Instead of returning the content of the inner "Group" the outer "Group" element matches. The approach of how to select this does not work and I suspect this might be a defect.

Please see the minimal example:

XML:

root:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <Group>
    <Name>Outer</Name>
    <Group>
      <Name>Inner</Name>
    </Group>
  </Group>
</Root>

(zip-xml/xml1-> root :Root :Group :Group :Name zip-xml/text)
"Outer"

Leiningen project with unit-tests as attachment. Run: lein test

$ lein test
lein test :only zip-xml-bug.core-test/parsing-group-elements

FAIL in (parsing-group-elements) (core_test.clj:34)
selecting the name of inner
expected: (= "Inner" (zip-xml/xml1-> root :Root :Group :Group :Name zip-xml/text))
  actual: (not (= "Inner" "Outer"))

Ran 1 tests containing 2 assertions.
1 failures, 0 errors.
Tests failed.


 Comments   
Comment by Benjamin Peter [ 20/Sep/16 2:41 PM ]

I found a "workaround" as you can see below and in zip-xml-bug-descent.tgz

(defn descent=
  [tagname]
  (fn [loc]
        (filter #(and (zip/branch? %) (= tagname (:tag (zip/node %))))

  (testing "selecting the name of inner using descent"
    (is (= "Inner"
           (-> (zip-xml/xml1-> root :Root :Group (descent= :Group) :Name zip-xml/text)))))

It seems the first expression in tag= matching the element itself in the or expression is the problem in my case. I suspect it can be used to select the root element. Is there any other need for it?

(defn tag=
  [tagname]
  (fn [loc]
    (or (= tagname (:tag (zip/node loc)))
        (filter #(and (zip/branch? %) (= tagname (:tag (zip/node %))))
(zf/children-auto loc)))))

Maybe there should be a self predicate instead?





Generated at Sun Dec 04 10:40:57 CST 2016 using JIRA 4.4#649-r158309.