Giter Club home page Giter Club logo

xpath's People

Contributors

ivan4th avatar lichtblau avatar ruricolist avatar scymtym avatar slyrus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

xpath's Issues

Can't read prefix of tag with "preceding-sibling::text()"

In the document I'm trying to parse tags often have pre- and suffixes
that I need to read (e.g ... [<sometag>FOO_BAR</sometag>] ... where
I need to get the "[" and "]" if they are present).
Reading suffixes by evaluating following-sibling::text() works like
I would expect in that it gives me the text directly after a tag.
However, when I try to read the prefix of a tag by evaluating
preceding-sibling::text() I get the text after the parent tag of the
tag instead of the text directly before the tag.

You can test the behaviour by running the following snippet:

(defparameter *document-text*
  "<foo>BAR-PREFIX<bar>BARTEXT</bar>BAR-SUFFIX=BAZ-PREFIX<baz>BAZTEXT</baz>BAZ-SUFFIX</foo>")

(defparameter *xml*
  (cxml:parse *document-text*
              (cxml:make-whitespace-normalizer
                (stp::make-builder))))

(format t "~a~%" *document-text*)

(xpath:do-node-set (node (xpath:evaluate "foo" *xml*))
  (let* ((bar-suffix (xpath:string-value (xpath:evaluate "bar/following-sibling::text()" node)))
         (baz-prefix (xpath:string-value (xpath:evaluate "baz/preceding-sibling::text()" node)))
         (baz-suffix (xpath:string-value (xpath:evaluate "baz/following-sibling::text()" node))))
    (format t "bar/following-sibling::text() - expected: \"BAR-SUFFIX=BAZ-PREFIX\", got: ~s~%" bar-suffix)
    (format t "baz/preceding-sibling::text() - expected: \"BAR-SUFFIX=BAZ-PREFIX\", got: ~s~%" baz-prefix)
    (format t "baz/following-sibling::text() - expected: \"BAZ-SUFFIX\"           , got: ~s~%" baz-suffix)))

I tested it on SBCL 2.0.1.debian with Quicklisp installed on Ubuntu
20.04 using the following command ("test.lisp" contains the snippet
above):

sbcl \
  --non-interactive \
  --eval "(progn (ql:quickload :xpath) (ql:quickload :cxml) (ql:quickload :cxml-stp))" \
  --load test.lisp \
  --eval "(sb-ext:quit)"

I'm relatively new to CL and it's my first time working with XPath
syntax, so if this behaviour is intended I apologize and would be
thankful for a hint as to how I can properly read text surrounding tags.

unble to quickload

when i run (ql:quickload :xpath) i get the following:

Lock on package COMMON-LISP violated when
proclaiming nil as a function while in package XPATH.
   [Condition of type symbol-package-locked-error]
See also:
  SBCL Manual, Package Locks [:node]
  Common Lisp Hyperspec, 11.1.2.1.2 [:section]

i'm pretty new to CL so not sure what's going on. is this library still functioning? it seems to be up to date in quicklisp/ultralisp.

Evaluate works in a surprising way when starting from a particular node.

If I call xpath:evaluate with a particular node, I don't expect the node-set iterator to map through that node's parents. Currently, if I evaluate the XPath expression //c using the first b node as context, I get all four c nodes back.

ICS->CSV> (let* ((xml (cxml:parse 
                       "<a><b><c>0</c></b><b><c>1</c></b><b><c>2</c></b><b><c>3</c></b></a>"
                       (cxml-stp:make-builder)))
                 (el (first (xpath:map-node-set->list 'identity
                                                      (xpath:evaluate "//b" xml)))))
            (xpath:map-node-set->list 'identity
                                      (xpath:evaluate "//c" el)))
(#.(CXML-STP:ELEMENT
    #| :PARENT of type ELEMENT |#
    :CHILDREN '(#.(CXML-STP:TEXT #| :PARENT of type ELEMENT |# :DATA "0"))
    :LOCAL-NAME "c")
 #.(CXML-STP:ELEMENT
    #| :PARENT of type ELEMENT |#
    :CHILDREN '(#.(CXML-STP:TEXT #| :PARENT of type ELEMENT |# :DATA "1"))
    :LOCAL-NAME "c")
 #.(CXML-STP:ELEMENT
    #| :PARENT of type ELEMENT |#
    :CHILDREN '(#.(CXML-STP:TEXT #| :PARENT of type ELEMENT |# :DATA "2"))
    :LOCAL-NAME "c")
 #.(CXML-STP:ELEMENT
    #| :PARENT of type ELEMENT |#
    :CHILDREN '(#.(CXML-STP:TEXT #| :PARENT of type ELEMENT |# :DATA "3"))
    :LOCAL-NAME "c"))

Cannot run the first example. `stp` does not exist.

After loading xpath, I can't run the preparation step out of the box, parsing the XML:

(defparameter *document*
	   (cxml:parse "<test a='1' b='2' xmlns:foo='http://foo'>
                          <child>hello world</child>
                          <foo:child>bar</foo:child>
                        </test>"
		       (stp:make-builder)))

=>

package STP does not exist.

It looks like cxml-stp is required.

Or if it isn't, what is an alternative to (stp:make-builder) ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.