Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 14 00:00
    scala-steward closed #143
  • Jul 13 23:59
    scala-steward commented #143
  • Jul 13 23:59
    scala-steward opened #144
  • Jul 11 23:31
    scala-steward opened #143
  • Jul 11 23:31
    scala-steward opened #142
  • Feb 16 12:07

    nrinaudo on update-sbt-1.6.2

    (compare)

  • Feb 16 12:05

    nrinaudo on master

    Update sbt to 1.6.2 Merge pull request #141 from nr… (compare)

  • Feb 16 12:05
    nrinaudo closed #141
  • Feb 16 11:43
    nrinaudo opened #141
  • Feb 16 11:43

    nrinaudo on update-sbt-1.6.2

    Update sbt to 1.6.2 (compare)

  • Feb 16 11:10

    nrinaudo on update-kantan.sbt-2.8.2

    (compare)

  • Feb 16 11:10

    nrinaudo on master

    Update to kantan.sbt 2.8.2 Merge pull request #140 from nr… (compare)

  • Feb 16 11:10
    nrinaudo closed #140
  • Feb 16 10:59
    nrinaudo opened #140
  • Feb 16 10:59

    nrinaudo on update-kantan.sbt-2.8.2

    Update to kantan.sbt 2.8.2 (compare)

  • Jan 13 17:59
    scala-steward closed #135
  • Jan 13 17:59
    scala-steward commented #135
  • Jan 13 17:59
    scala-steward opened #139
  • Dec 21 2021 05:16
    scala-steward closed #137
  • Dec 21 2021 05:16
    scala-steward commented #137
Nicolas Rinaudo
@nrinaudo
because if so, you can absolutely execute an xpath query on a Document and get the result(s) as Nodes. If you know how to do the rest, you're set.
by the same token, if you know how to modify the content of a Node, you could get an xpath query running that'd return your target Node and update that
I'll be blunt though: I've no intention of wrapping Node, Document and co. in proper Scala types. If you want to implement your use cases within the scope of kantan.xpath, you'll have to deal with "low level" Java types :)
Brandon Elam Barker
@bbarker
@nrinaudo thanks - while I haven't done that before, I believe you've basically confirmed by plan based on what I have read earlier today
Nicolas Rinaudo
@nrinaudo
I'm not 100% sure it's possible - I haven't done Java in years, and still wake up in cold sweat from nightmares about java.xml.*
Brandon Elam Barker
@bbarker
oh thanks, I found another SO link with some suggestions along those lines, I think - https://stackoverflow.com/questions/6124239/how-to-update-xml-using-xpath-and-java - but haven't had a chance to go through it in detail yet
Nicolas Rinaudo
@nrinaudo
So looks like it should be possible, maybe even not too hard, although not necessarily straightforward. Let me know if you get stuck!
Brandon Elam Barker
@bbarker
ok, many thanks! I do not know if I'll be using Kantan at this stage as we're only going for removal of nodes right now, but late on we may plan to get more sophisticated and do updates as well, at which point I think Kantan XPath could be quite helpful
Nicolas Rinaudo
@nrinaudo
If you’re just doing removal, kantan.xpath is probably not terribly useful :)
Brandon Elam Barker
@bbarker
well, I have more XML projects that I would like to admit so there is a fair chance I will use it soon ... ( though I'm in the process of removing JAXB/XSD/XML from one Java project I converted to Scala ... nightmares indeed)
Nicolas Rinaudo
@nrinaudo
fair warning though: if you're trying to get rid of all the Java stuff in order to add support, among other things, to scala.js: kantan.xpath cannot support non-JVM backends, since it's basically a thin wrapper over java.xml.xpath
Howy Perrin
@howyp

Have just found this, looks great so far. Am a bit stuck with doing fall-back resolutions on case classes, I want to be able to do an orElse, something like:

case class Example(a: String, b: String)

NodeDecoder.decode(
  xp”//a”,
  xp”//b”.orElse(xp”//c”)
)(Example.apply)

Is there a neat way to do something like that?

Nicolas Rinaudo
@nrinaudo
isn't that something you can do directly in xpath? //b|c ?
(haven't tried it, it's something I vaguely seem to remember from when I did a lot more xpath than nowadays)
Howy Perrin
@howyp
thanks - I’ll give it a go :-)
From what I can see | is a union operator in XPath - selects these nodes OR those nodes
do you know what version of XPath is supported by kantan.xpath?
Nicolas Rinaudo
@nrinaudo
that's what I thought you meant to do, so I must have misunderstood your problem
not entirely sure, whatever is supported by the JVM
Howy Perrin
@howyp
sorry I’m not explaining myself well. It’s like UNION in SQL - returns all results from the first expression, followed by all from the second expression
Nicolas Rinaudo
@nrinaudo
but basically, if there's no way to do this at the XPath level, you're out of luck - this isn't a use case supported by kantan.xpath
Howy Perrin
@howyp
So after a bit of playing around I can do roughly what I’m after with using expressions like this rather than just the XPath:
Query(xp"(//a")(Compiler.xpath1(NodeDecoder[String].recover { case _ => "" }))
I guess I could use .orElse(…) and another query if I wanted
I couldn’t work out why the Compiler.xpath1 call was needed - in other places it looks as if it acts as an implicit conversion
Nicolas Rinaudo
@nrinaudo
you're forcing me to look at code I've not read in.. years, I think :)
Howy Perrin
@howyp
haha! You’re welcome ;-)
Philippe Derome
@phderome
hello, saw some SO entry yesterday about kantan.xpath.
Nicolas Rinaudo
@nrinaudo
Probably authored by me, to be honest. It’s not exactly a popular library
Xml isn’t a thing that happens much in Scala world
Philippe Derome
@phderome
Yes indeed, this might be relevant to me someday as we use some XML at work
Nicolas Rinaudo
@nrinaudo
well, feel free to ask questions you might have about the project here, that's what it's made for. I try to keep the documentation comprehensive and up to date, so I encourage you to have a look if you'd like to learn more and see if it fits your needs
(and to have a look at its sister projects, kantan.regex and kantan.csv, for basically the same library, but for regular expressions and csv)
Philippe Derome
@phderome
hey I am interested in doing somewhat user-friendly XML diff of two documents programmatically. I found a number of useful references on the Java side and before I use them, I am curious as to whether some or much of it is already available in kantan.xpath. The input XML documents are created with a PrettyPrinter and thus have newlines in reasonable places. So the input to diff is pretty-printed XML docs (an assumption I can make that one would normally not make). I am looking at setting client data of line number with each node in the 2 XML documents I am comparing (I found this: https://eyalsch.wordpress.com/2010/11/30/xml-dom-2/). And finally XMLUnit for Java 2.x seems to have sufficient flexibility for what I am trying to do, namely order of child nodes is not important for comparison (something called DifferenceEvaluators.downgradeDifferencesToEqual(ComparisonType.CHILD_NODELIST_SEQUENCE)))
The general gist of what I am trying to do is something similar to Unix diff but accounting for some of the above requirements, showing what is different on both sides, what exists only one side and the line numbers associated with the nodes that appear in the report.
Nicolas Rinaudo
@nrinaudo
Honestly, as much as I’d like to advocate my lib here, it does nothing that can help you
Philippe Derome
@phderome
that is all right.
Nicolas Rinaudo
@nrinaudo
Kantan.xpath only lets you evaluate xpath expressions against an xml document
Philippe Derome
@phderome
+1
Nicolas Rinaudo
@nrinaudo
The point being to get rid of the xml and turn it into useful typed as soon as possible, which is preciseky what you want not to do
Philippe Derome
@phderome
ha ha!
Nicolas Rinaudo
@nrinaudo
(Sorry about the typos, typing on a phone with a baby in one arm)
Philippe Derome
@phderome
no worries, and if we'd be speaking French here, you would not see the proper accents as I am on a US keyboard at work and cannot bother to make it multilingual
Stefan Endrullis
@xylo
Hi. I just searched for an xpath scala library again and stumbled over your project. And wow I'm really surprised! This project is fucking genius! - The compile time errors for xpath expressions, the automatic and intelligent type conversions, how trivial it is to define implicit decoders, ... This is just great and all I ever wanted! Thanks a lot!
Is there actually an overview over all kantan libs/projects?
Nicolas Rinaudo
@nrinaudo
Great to hear this is useful!
No overview yet, but the only directly useful ones are csv, xpath and regex
I’ve not updated them much recently because they’re pretty much done, but they could use a bit of love... just need to motivate myself