How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

interpretive language scripts


Moderator: Forum moderators

Locked
User avatar
peebee
Posts: 1621
Joined: Mon Jul 13, 2020 10:54 am
Location: Worcestershire, UK
Has thanked: 157 times
Been thanked: 706 times
Contact:

How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by peebee »

Is it possible using XMLStarlet + an XPath specification to extract a single node from an index.plist file (like the attached)?

A single node xxxx is contained between:
<key>xxxx</key>
<dict>
................
</dict>

Thanks!
p.s. background - index.plist is the way Void Linux produces it's repo database and I want to produce a Void equivalent of /var/packages/woof-installed-packages
p.p.s XMLStarlet can be downloaded via pkgs.org - I'm using the Void download

Attachments
index.plist-false.gz
(6.3 KiB) Downloaded 64 times
Last edited by Flash on Sun Dec 19, 2021 4:59 pm, edited 2 times in total.
Reason: Original title: [FIXED] XML - XPath - XMLStarlet help

Builder of LxPups, SPups, UPup32s, VoidPups; LXDE, LXQt, Xfce addons; Chromium, Firefox etc. sfs; & Kernels

User avatar
Keef
Posts: 270
Joined: Tue Dec 03, 2019 8:05 pm
Has thanked: 3 times
Been thanked: 75 times

Re: XML - XPath - XMLStarlet help needed

Post by Keef »

Poking around in the dark here a bit, but this is what I got. Couldn't get any output at all using the examples on the link you provided, but tried something from here: https://superuser.com/questions/1026933 ... e-xml-file
(Just showing output for first package)

Code: Select all

# xmlstarlet sel -t -v '//dict/key'  index.plist
Attempt to load network entity http://www.apple.com/DTDs/PropertyList-1.0.dtd
0ad
architecture
filename-sha256
filename-size
homepage
installed_size
license
maintainer
pkgver
run_depends
shlib-requires
short_desc
source-revisions
....
User avatar
Keef
Posts: 270
Joined: Tue Dec 03, 2019 8:05 pm
Has thanked: 3 times
Been thanked: 75 times

Re: XML - XPath - XMLStarlet help needed

Post by Keef »

This may be better: :oops:

Code: Select all

# xmlstarlet sel -t -v '/plist/dict/key' -nl index.plist
Attempt to load network entity http://www.apple.com/DTDs/PropertyList-1.0.dtd
0ad
0ad-data
2048-qt
2bwm
User avatar
peebee
Posts: 1621
Joined: Mon Jul 13, 2020 10:54 am
Location: Worcestershire, UK
Has thanked: 157 times
Been thanked: 706 times
Contact:

Re: XML - XPath - XMLStarlet help needed

Post by peebee »

Thanks @Keef

I've managed to do what I want with some script..... e.g.

Code: Select all

#!/bin/sh
pkg=2048-qt

pkg="<key>${pkg}</key>"
begnum=`grep -n $pkg index.plist | head -1 | cut -d : -f 1`
finnum=`tail -n +"$begnum" index.plist | grep -n "	</dict>" | head -1 | cut -d : -f 1`
finnum=`expr $begnum + $finnum - 1`

sed -n "${begnum},${finnum}p" index.plist

I'll see what the speed is like - index.plist from Void is 15MB!

Builder of LxPups, SPups, UPup32s, VoidPups; LXDE, LXQt, Xfce addons; Chromium, Firefox etc. sfs; & Kernels

jamesbond
Posts: 713
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 399 times

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by jamesbond »

Use xmllint which is part of libxml2, which is part of most distros.
You can use XMLStarlet if you want, the XPath is the same whichever XML tool you use (it's a standard, after all).

For example, to retrieve details about package "0ad" from index.plist, do this

Code: Select all

xmllint --xpath '/plist/dict/key[text()="0ad"]/following-sibling::dict[1]' index.plist

To get the same thing for "rox" package (the beloved rox filer):

Code: Select all

xmllint --xpath '/plist/dict/key[text()="rox"]/following-sibling::dict[1]' index.plist

To match the output of your example, it's just a matter of re-building the missing elements (of which you know all the details already).

The complete code for extract the package looks like this:

Code: Select all

#$1-package to extract, $2-path to index.plist
extract() {
	local pkg=$1 plist="$2"
	cat << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>$pkg</key>
$(xmllint --xpath '/plist/dict/key[text()="'$pkg'"]/following-sibling::dict[1]' "$plist")
</dict>
</plist>
EOF
}

_________________

Out of topic rant: (since peebee already SOLVED/CLOSED the main topic anyway):

When posting this, I want to reference my post that performs the conversion of Void's index.plist to PPM package database. And tell you what, I'm very surprised that I cannot find my own post. In fact, it seems that the whole thread about the "Let's build a Community Puppy" has completely disappeared.

This is disheartening.

I spent time to experiment and wrote that script, and then posted it. The time that I could never recover back. It was a time worthwhile spent, because, I thought, others could see and learn from it.

And now, through no fault of my own, because of other bickering personalities that has nothing to do with me or with the original post, that thread has now disappeared. I saw it when the thread was locked, and I thought it was good enough - but no, the entire thread HAS to go down the drain too.

Please, answer me: why would I bother to post anything in the future, if my posts can be taken down because others happen to pollute the thread?

Why does the thread have to go, anyway? Is it because we're ashamed that we're not a shining example of peace to the world? Is it because we're ashamed that we're not as civil as the image we try to project?

Here's a suggestion: if a thread gets too hot, by all means, LOCK IT. If you have the time and motivation to edit/remove the irrelevant posts, by all means, do that. In fact, do that right after the insults are posted, so things don't accumulate and it gets too difficult to separate the chaff from the wheat.

But please, don't take it down. Don't hide it. EVER. Leave it, for everybody to see, to learn from it.

Disagreements are part of everyday life, sometimes, even strong disagreements. We can't all agree at all time. Sometimes disagreement can be civil, sometimes it isn't. It happens even to people with the best intentions. Even to the nicest forum in the known galaxy: this forum.

To hide it is the same as not admitting that we have disagreements, pretending that we're better than what we actually are. But we know we're fooling no one. That Puppy Linux Community isn't ideal, because its members are not ideal either. We are friendly, but we should not try to show a friendly facade by sweeping the dirt under the carpet.

The same thing had happened in the old forum, and I can happily share with you that it was one of the reasons why I gradually stopped posting. Because there is really no point spending 1-2 hours writing a guide to help a newbie, when someone could just come, throw insults, and then entire thread disappears.

Merry Christmas everybody, and please, be civil.
Even if you disagree with one another.

User avatar
peebee
Posts: 1621
Joined: Mon Jul 13, 2020 10:54 am
Location: Worcestershire, UK
Has thanked: 157 times
Been thanked: 706 times
Contact:

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by peebee »

Hi @jamesbond

I was also disappointed that your post / attachment had disappeared - I think @bigpup must have decided to delete the whole thread - and has the ability to so do as a Moderator.

I have a copy of your script and am using it in the VoidPup32 endeavour - I have thanked you in the thread. viewtopic.php?t=4741

Thank you for your further guidance which is much appreciated.

Cheers & Seasons Greetings
PeeBee

Builder of LxPups, SPups, UPup32s, VoidPups; LXDE, LXQt, Xfce addons; Chromium, Firefox etc. sfs; & Kernels

one
Posts: 244
Joined: Sun Jul 12, 2020 7:53 am
Has thanked: 16 times
Been thanked: 59 times

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by one »

jamesbond wrote: Mon Dec 20, 2021 10:15 am

[...]
Why does the thread have to go, anyway? Is it because we're ashamed that we're not a shining example of peace to the world? Is it because we're ashamed that we're not as civil as the image we try to project?

Here's a suggestion: if a thread gets too hot, by all means, LOCK IT. If you have the time and motivation to edit/remove the irrelevant posts, by all means, do that. In fact, do that right after the insults are posted, so things don't accumulate and it gets too difficult to separate the chaff from the wheat.

But please, don't take it down. Don't hide it. EVER. Leave it, for everybody to see, to learn from it.

Disagreements are part of everyday life, sometimes, even strong disagreements. We can't all agree at all time. Sometimes disagreement can be civil, sometimes it isn't. It happens even to people with the best intentions. Even to the nicest forum in the known galaxy: this forum.

To hide it is the same as not admitting that we have disagreements, pretending that we're better than what we actually are. But we know we're fooling no one. That Puppy Linux Community isn't ideal, because its members are not ideal either. We are friendly, but we should not try to show a friendly facade by sweeping the dirt under the carpet.
[...]
Merry Christmas everybody, and please, be civil.
Even if you disagree with one another.

Thank you @jamesbond for your wise words ...

peace

User avatar
rockedge
Site Admin
Posts: 6481
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2693 times
Been thanked: 2592 times
Contact:

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by rockedge »

I looked at the Mod Logs and yes. Theoretically I could go through hoops to retrieve it through a database backup, but it is complicated and tricky to achieve successfully. I am surprised it's gone! I thought Locked and it was good to go.

phpBB 3+ does not support a "Trash Can" feature with any restore function, deleted is deleted.

User avatar
fredx181
Posts: 2997
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 364 times
Been thanked: 1272 times
Contact:

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by fredx181 »

Fully agree with @jamesbond and the moderator who did delete that thread should be deeply ashamed. :cry:

EDIT: Looked it up in the logs now and indeed it was @bigpup who deleted it, with reason "topic no longer needed"
Not for you to decide if a topic is needed or not, bigpup ! (even when you started it yourself)

williwaw
Posts: 1909
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 168 times
Been thanked: 354 times

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by williwaw »

another forum I frequent has the ability for a mod to move a topic to an "admin only" review area. and restore it after edits are reviewed by the mods.

is there anything similar in phpBB 3+ ?

User avatar
Wiz57
Moderator
Posts: 562
Joined: Fri Dec 13, 2019 3:54 pm
Location: Chickasha, OK USA
Has thanked: 77 times
Been thanked: 113 times

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by Wiz57 »

williwaw wrote: Mon Dec 20, 2021 5:42 pm

another forum I frequent has the ability for a mod to move a topic to an "admin only" review area. and restore it after edits are reviewed by the mods.

is there anything similar in phpBB 3+ ?

Yes, there is...and we have a forum area currently, though none of the moderators or admins have used the "move topic" to that area YET.
I looked, and as rockedge mentioned, there doesn't appear to be any way outside of tedious/time consuming searching the databases to
find those topics that were deleted.
Well, guess it's time for me to go back into "silent mode" because there are some here that think I should just be quiet and handle spam/spammers.
Wiz :lol:

Signature available upon request

jamesbond
Posts: 713
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 399 times

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by jamesbond »

peebee wrote: Mon Dec 20, 2021 10:51 am

I have a copy of your script and am using it in the VoidPup32 endeavour - I have thanked you in the thread. viewtopic.php?t=4741

Thank you for your further guidance which is much appreciated.

You are very much welcome.

rockedge wrote: Mon Dec 20, 2021 3:09 pm

I looked at the Mod Logs and yes. Theoretically I could go through hoops to retrieve it through a database backup, but it is complicated and tricky to achieve successfully.
I am surprised it's gone! I thought Locked and it was good to go.

Don't bother Erik. I understand that mistakes happen, especially for new mods (oh look awesome POWERRR), but as cliche as it sounds, "with great power comes great responsibility".

I just hope that it doesn't happen again.

Wiz57 wrote: Mon Dec 20, 2021 10:22 pm

I looked, and as rockedge mentioned, there doesn't appear to be any way outside of tedious/time consuming searching the databases to
find those topics that were deleted.

Don't bother with that. I appreciate you and the other fellow mods doing the housekeeping here. It won't be the same without all your hard work.

Just remember that people also spent their time to form their thoughts and responses, typed and formatted them before posting them here. As I said, edit/remove offending posts by all means (we have house rules after all), but please be a lot more considerate before deleting an __entire__ thread (especially now we know that deletion is permanent) :shock:

User avatar
peebee
Posts: 1621
Joined: Mon Jul 13, 2020 10:54 am
Location: Worcestershire, UK
Has thanked: 157 times
Been thanked: 706 times
Contact:

Re: How to extract a single node from an index.plist using XMLStarlet + XPath? (Solved)

Post by peebee »

@rockedge @mikewalsh @Wiz57

Please lock this topic as it is both "Solved" and now Off-Topic. Thanks.

Builder of LxPups, SPups, UPup32s, VoidPups; LXDE, LXQt, Xfce addons; Chromium, Firefox etc. sfs; & Kernels

Locked

Return to “Scripts”