OVH Cloud OVH Cloud

XPath dans xmllint (sans shell)?

2 réponses
Avatar
Neil McNaughton
Sous xmllint --shell ... il y a un parseur xpath tres utile - par exemple on
peut faire //body pour n'avoir que le "body" d'un doc html.

Mais comment faire pareil sur la ligne de commande? Cherche un one liner
sous shell pour capter les contenus d'un tag <body> XXXX </body>... De pref
sans passer par perl...

Neil

2 réponses

Avatar
Stephane Chazelas
2005-01-7, 13:11(+01), Neil McNaughton:
Sous xmllint --shell ... il y a un parseur xpath tres utile - par exemple on
peut faire //body pour n'avoir que le "body" d'un doc html.

Mais comment faire pareil sur la ligne de commande? Cherche un one liner
sous shell pour capter les contenus d'un tag <body> XXXX </body>... De pref
sans passer par perl...
[...]


Pas testé:

$ apt-cache show xmlstarlet
Package: xmlstarlet
Priority: optional
Section: text
Installed-Size: 324
Maintainer: Alex Mauer
Architecture: i386
Version: 0.9.3-4
Depends: libc6 (>= 2.3.2.ds1-4), libgcrypt11, libxml2 (>= 2.6.11), libxslt1.1 (>= 1.1.8), zlib1g (>= 1:1.2.1)
Filename: pool/main/x/xmlstarlet/xmlstarlet_0.9.3-4_i386.deb
Size: 137782
MD5sum: 4e905a58da64831277e81fdc41d74093
Description: Command Line XML Toolkit
XMLStarlet is a set of command line utilities (tools) which can be used to
transform, query, validate, and edit XML documents and files using simple set
of shell commands in similar way it is done for plain text files using
UNIX grep, sed, awk, diff, patch, join, etc commands.
.
This set of command line utilities can be used by those who deal with many XML
documents on UNIX shell command prompt as well as for automated XML processing
with shell scripts.
.
The toolkit's feature set includes options to:
Check or validate XML files (simple well-formedness check, DTD, XSD, RelaxNG)
Calculate values of XPath expressions on XML files (such as running sums, etc)
Search XML files for matches to given XPath expressions
Apply XSLT stylesheets to XML documents (including EXSLT support, and passing
parameters to stylesheets)
Query XML documents (ex. query for value of some elements of attributes,
sorting, etc)
Modify or edit XML documents (ex. delete some elements)
Format or "beautify" XML documents (as changing indentation, etc)
Fetch XML documents using http:// or ftp:// URLs
Browse tree structure of XML documents (in similar way to 'ls' command for
directories)
Include one XML document into another using XInclude
XML c14n canonicalization
Escape/unescape special XML characters in input text
Print directory as XML document
Convert XML into PYX format (based on ESIS - ISO 8879), and vice versa

--
Stephane

Avatar
drkm
Stephane Chazelas writes:

[ X-Post et Fu2 fr.comp.text.xml, qui me semble plus approprié. ]

2005-01-7, 13:11(+01), Neil McNaughton:

Sous xmllint --shell ... il y a un parseur xpath tres utile - par exemple on
peut faire //body pour n'avoir que le "body" d'un doc html.

Mais comment faire pareil sur la ligne de commande? Cherche un one liner
sous shell pour capter les contenus d'un tag <body> XXXX </body>... De pref
sans passer par perl...


[...]

Pas testé:

$ apt-cache show xmlstarlet


[...]

Merci pour le lien. Ça a l'air pas mal, à première vue. Le genre
d'outils en CLI qui me manque parfois. Je ne l'ai pas encore installé
(je ne sais pas, ici), mais ce que cherche le PO se résumerait alors,
si j'ai bien compris, à :

~> xml sel -t -c '//body'

ou (je ne suis pas sûr de ce qu'il souhaite) :

~> xml sel -t -c '//body/*'

Sympa.

--drkm