revxml

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: revxml

Post by mwieder » Fri Jun 28, 2013 7:14 pm

Done. Still some cleanup to do, but...

There are now two new xpath functions:

revEvaluateXPath(pDocID, pXpathExpression)
revDataFromXPathQuery(pDocID, pXpathExpression)

so that given pDocID =

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="COOKING">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>
<book category="CHILDREN">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>
<book category="WEB">
  <title lang="en">XQuery Kick Start</title>
  <author>James McGovern</author>
  <author>Per Bothner</author>
  <author>Kurt Cagle</author>
  <author>James Linn</author>
  <author>Vaidyanathan Nagarajan</author>
  <year>2003</year>
  <price>49.99</price>
</book>
<book category="WEB">
  <title lang="en">Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
</book>
</bookstore>

Code: Select all


pXpathExpression = /bookstore/book[price<50]
put revEvaluateXPath(pDocID, pXpathExpression) -- gives you
/bookstore/book[1]
/bookstore/book[2]
/bookstore/book[3]
/bookstore/book[4]

and
pXpathExpression = /bookstore/book[price<30]/title
put revDataFromXPathQuery(pDocID, pXpathExpression) -- gives you
Harry Potter

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: revxml

Post by monte » Fri Jun 28, 2013 9:57 pm

Cool.... should they have the revXML prefix?

Also it would be nice if you could specify the delimiter between the returned data in the data version...
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: revxml

Post by mwieder » Fri Jun 28, 2013 11:13 pm

Good idea.
The function names are now getting a bit wordy, but are

revXMLEvaluateXPath(pDocID, pXpathExpression [, delimiter])
revXMLDataFromXPathQuery(pDocID, pXpathExpression [, delimiter])

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: revxml

Post by malte » Fri Jun 28, 2013 11:34 pm

I really really like this Mark!

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: revxml

Post by mwieder » Wed Jul 03, 2013 5:05 am

Pull request submitted.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: revxml

Post by Janschenkel » Wed Jul 03, 2013 5:59 am

Thanks for exposing this, Mark - and just think of all the other good stuff lurking in there: XSL translformation, schema validation, etc. :-)

Cheers,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: revxml

Post by mwieder » Wed Jul 03, 2013 5:20 pm

I stopped short of schema validation because it's only partially implemented in the libxml library itself. If I went down this road now I'd be running parallel with the work going on there, and I'd rather wait until it's fleshed out in the library. [translation: I'm lazy and I'd rather have them do the work in the library instead].

And while what I really want out of this is XSLT and XQuery support, that's a layer on top of libxml. I'm looking around for properly-licensed libraries to graft on. If you know of any, please steer me in that direction.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: revxml

Post by Janschenkel » Wed Jul 03, 2013 9:15 pm

Hi Mark,

I thought libxslt would do fine, as it is a layer on top of libxml2 - and it is also available under an MIT license.
But I have to admit I'm not that familiar with the libxml project.

Jan SchenKel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: revxml

Post by mwieder » Wed Jul 03, 2013 10:14 pm

I looked at libxslt earlier, and it's probably a good fit. I'm not sure how the MIT-LGPL2 licensing schemes fit together, though.

Update... OK - I missed the part about libxml itself being MIT-licensed. I guess I'm ok to go take a shot at libxslt now.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: revxml

Post by Janschenkel » Thu Jul 04, 2013 5:45 am

Woo - go Mark! :-)

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: revxml

Post by mwieder » Wed Jul 17, 2013 6:42 pm

I just came across two undocumented but implemented xml calls:

Code: Select all

revCopyRemoteXMLNode
revMoveRemoteXMLNode
It appears that maybe they copy or move xml elements from one xml tree to another, given that the syntax seems to be

Code: Select all

revCopyRemoteXMLNode srcID, node, dstID, node, [before|after], [child|sibling]
revMoveRemoteXMLNode srcID, node, dstID, node, [before|after], [child|sibling]

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1207
Joined: Thu Apr 11, 2013 11:27 am

Re: revxml

Post by LCMark » Wed Jul 17, 2013 6:48 pm

Hmmm - they sound vaguely familiar - I think I added them as a favour to @malte an age ago... I expect it might have been before we had a good release notes process (including documenting things there that were 'experimental') so they got forgotten about and never documented.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: revxml

Post by mwieder » Thu Jul 18, 2013 2:39 am

OK - I'm going to leave them alone for now.

I just made a change and could use some opinions on it (especially from runrevmark).
The stock libxml library returns the contents of a node as a single text string. All content runs together, so that if you have

Code: Select all

<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<date>2003</date>
<price>29.95</price>
</book>
and you call GetNodeContents you end up with

"Harry PotterJ K. Rowling200329.95".

This seems less than optimum, so I modified libxml's internal concatenation routine with a one-line change to put a newline after each item. Now it returns

Harry Potter
J K. Rowling
2003
29.95

which seems more reasonable to me.

So my question: is there anything that this could mess up? Concatenating the data elements all together with no delimiters doesn't seem like a useful way to return the data elements, so it's hard for me to imagine a situation in which anyone would be currently relying on this.

Also, if we update to a newer version of the libxml third-party library we'd have to make the same one-line change there. Not that it's a big deal, but it's one more thing to have to maintain.

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: revxml

Post by monte » Thu Jul 18, 2013 3:01 am

It really would be nice if all these dependencies were submodules... yeah, I know submodules suck but they do serve a purpose. In this case the master branch of the submodule might contain the original and there might be a branch that we use for builds with any modifications. That way eventually we could add a remote of the actual repo for libxml etc and keep our version updated by merging to our build branch...
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: revxml

Post by mwieder » Thu Jul 18, 2013 3:12 am

Yeah. I've got an xpath branch in my livecode repository and then an xpath branch in my local thirdparty repository, so I've got a local submodule. Things can get pretty convoluted.

Locked

Return to “Engine Contributors”