|
From: Benito v. d. Z. <be...@be...> - 2020-07-17 19:36:54
|
Hi Reino, > > It would be really cool if you could turn Xidel into an editing-tool, > with updating/inserting/removing element/attribute/text-nodes at the > basics. Especially since it's not easy at all to use transform(). That is better implemented as extra library module. If I put it in Xidel, people would expect the standard XQuery Update, but that is probably full of weird W3C things, which take too long to implement. I thought about writing an XQuery editing module, but now I have found that someone already made one. It only needs slight adjustments for Xidel: https://github.com/benibela/XQuery-XML-Memory-Operations#pure-xquery-31 Although it currently seems to trigger some kind of namespace bug in Xidel, causing it to insert useless namespace declarations. > Apart from XMLStarlet, which hasn't been updated in 6 years (it can't > even edit 'xml_edit-test.xml') And it is correct to refuse the file. That file is not a valid XML file. In an XML file there must be exactly one element that is not a child of another element. If Xidel had a correct XML parser, it could not open that file either. Cheers, Benito On 05.07.20 22:40, Reino Wijnsma wrote: > Hello Benito, > > On 2020-07-05T17:25:07+0200, Benito van der Zander > <be...@be...> wrote: >> I forgot about this >> It should be fixed now > > Confirmed with xidel-0.9.9.20200705.7422.ad3f9fd36363: > > $ xidel xml_edit-test.xml -se > 'serialize(transform(/,function($x){$x/(if (empty(*) and > empty(text()[normalize-space()]) and not(self::text())) then () else > $x)}),map{"indent":true()})' > <a> > <x>string</x> > </a> > <a> > <x>string</x> > </a> > > Thanks. Lots of code (I saw in the commit) btw for just removing 2 > lines! :O > --- > > A bit of wishful thinking... > > 'test.xml': > <?xml version="1.0"?> > <test> > <a>10</a> > </test> > > xmlstarlet-1.6.1-win32.exe ed -u "//a" -v 20 test.xml # Update > text-node. > <?xml version="1.0"?> > <test> > <a>20</a> > </test> > > xmlstarlet-1.6.1-win32.exe ed -a "//a" -t elem -n a -v 20 test.xml # > Append new element. > <?xml version="1.0"?> > <test> > <a>10</a> > <a>20</a> > </test> > > xmlstarlet-1.6.1-win32.exe ed -d "//a" test.xml # Remove element. > <?xml version="1.0"?> > <test/> > > xmlstarlet-1.6.1-win32.exe ed -P -d "//a" test.xml # Remove element > and preserve white-space. > <?xml version="1.0"?> > <test> > > </test> > > Apart from XMLStarlet, which hasn't been updated in 6 years (it can't > even edit 'xml_edit-test.xml'), I'm not aware of any other up-to-date > command-line-tool that can edit xml-files without too much trouble. > It would be really cool if you could turn Xidel into an editing-tool, > with updating/inserting/removing element/attribute/text-nodes at the > basics. Especially since it's not easy at all to use transform(). > If such a project is way too much of an effort, then forget about it. > But if you'd at least give it a thought, that would be great. > -- > Reino > > > _______________________________________________ > Videlibri-xidel mailing list > Vid...@li... > https://lists.sourceforge.net/lists/listinfo/videlibri-xidel |