You are not logged in.

#1 2024-02-22 08:42:22

simonhiggs
Member
Registered: 2015-02-16
Posts: 12

Parsing an XML file

Hello,
I'm attempting to write a PKGBUILD file for logitechmediaserver (stable version).

The source URL is in this file

https://github.com/LMS-Community/lms-se … stable.xml

<servers><win64 url="https://downloads.slimdevices.com/nightly/LogitechMediaServer-8.4.1-1708338002-win64.exe" version="8.4.1" revision="1708338002" size="16 MB"/><win url="https://downloads.slimdevices.com/nightly/LogitechMediaServer-8.4.1-1708338002.exe" version="8.4.1" revision="1708338002" size="70 MB"/><osx url="https://downloads.slimdevices.com/nightly/LogitechMediaServer-8.4.1-1708338002.pkg" version="8.4.1" revision="1708338002" size="44 MB"/><rpm url="https://downloads.slimdevices.com/nightly/logitechmediaserver-8.4.1-0.1.1708338002.noarch.rpm" version="8.4.1" revision="1708338002" size="87 MB"/><tararm url="https://downloads.slimdevices.com/nightly/logitechmediaserver-8.4.1-1708338002-arm-linux.tgz" version="8.4.1" revision="1708338002" size="56 MB"/><nocpan url="https://downloads.slimdevices.com/nightly/logitechmediaserver-8.4.1-1708338002-noCPAN.tgz" version="8.4.1" revision="1708338002" size="17 MB"/><src url="https://downloads.slimdevices.com/nightly/logitechmediaserver-8.4.1-1708338002.tgz" version="8.4.1" revision="1708338002" size="119 MB"/><deb url="https://downloads.slimdevices.com/nightly/logitechmediaserver_8.4.1~1708338002_all.deb" version="8.4.1" revision="1708338002" size="57 MB"/><debamd64 url="https://downloads.slimdevices.com/nightly/logitechmediaserver_8.4.1~1708338002_amd64.deb" version="8.4.1" revision="1708338002" size="25 MB"/><debarm url="https://downloads.slimdevices.com/nightly/logitechmediaserver_8.4.1~1708338002_arm.deb" version="8.4.1" revision="1708338002" size="32 MB"/><debi386 url="https://downloads.slimdevices.com/nightly/logitechmediaserver_8.4.1~1708338002_i386.deb" version="8.4.1" revision="1708338002" size="18 MB"/></servers>

Specifically this part

<src url="https://downloads.slimdevices.com/nightly/logitechmediaserver-8.4.1-1708338002.tgz" version="8.4.1" revision="1708338002" size="119 MB"/>

What's the best way to extract url, version and revision?

Thank you. Simon.

Last edited by simonhiggs (2024-02-22 08:42:47)

Offline

#2 2024-02-22 08:59:17

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,687

Re: Parsing an XML file

There is an existing package: https://aur.archlinux.org/packages/logitechmediaserver
Any reason why you're creating a new one?

Offline

#3 2024-02-22 09:03:46

simonhiggs
Member
Registered: 2015-02-16
Posts: 12

Re: Parsing an XML file

The existing package is for the Logitech 8.4.0 release. I want to follow the 8.4.1 Community (stable) version.

Offline

#4 2024-02-22 09:19:29

loqs
Member
Registered: 2014-03-06
Posts: 18,922

Re: Parsing an XML file

Have you looked at xq for the XML parsing? Although the data also appears to be available through JSON and for that you could use jq.

simonhiggs wrote:

The existing package is for the Logitech 8.4.0 release. I want to follow the 8.4.1 Community (stable) version.

The 8.4.1 is a nightly build of the 8.4 branch until 8.4.1 is released?

Offline

#5 2024-02-22 14:02:43

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,459
Website

Re: Parsing an XML file

sed 's/.*<src url="\([^"]*\)".*/\1/' original.xml

This is the url - but the version and revision are included in it already.

Last edited by Trilby (2024-02-22 14:06:27)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2024-02-22 15:24:30

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,653
Website

Re: Parsing an XML file

You can also use xmlstarlet and require it as a build dependency:

$ curl https://raw.githubusercontent.com/LMS-Community/lms-server-repository/master/stable.xml | xmlstarlet sel -t -v "/servers/src/@url" -

Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#7 2024-02-22 20:00:56

simonhiggs
Member
Registered: 2015-02-16
Posts: 12

Re: Parsing an XML file

loqs wrote:

Have you looked at xq for the XML parsing?

Thanks for this, and the other suggestions too.

simon@macmini ~ % curl -s -L https://github.com/LMS-Community/lms-server-repository/raw/master/stable.xml | xq -e /servers/src/@url
https://downloads.slimdevices.com/nightly/logitechmediaserver-8.4.1-1708338002.tgz

Offline

#8 2024-02-23 12:52:51

tekstryder
Member
Registered: 2013-02-14
Posts: 552

Re: Parsing an XML file

Trilby wrote:
sed 's/.*<src url="\([^"]*\)".*/\1/' original.xml

This reminded me of my favorite Stack Overflow answer.

That one had me in tears when first read back in the day.

Offline

Board footer

Powered by FluxBB