Il y a 389 articles et 19 utilisateurs inscrits (ce bandeau est défini dans MediaWiki:Sitenotice)

« Xml Tester des XPath » : différence entre les versions

De AJLSM
Aller à la navigation Aller à la recherche
création+catégories
 
→XMLStarlet : Exemple avancé
Ligne 13 : Ligne 13 :


=== XMLStarlet ===
=== XMLStarlet ===
On peut également utiliser [http://xmlstar.sourceforge.net/ XMLStarlet], qui est open source, gratuit. Et disponible sur Windows et Linux.
On peut également utiliser [http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html XMLStarlet], qui est open source, gratuit. Et disponible sur Windows et Linux.
<syntaxhighlight lang="bash">xmlstarlet sel -t -v "count(/xml/table/rec/numField)" table.xml</syntaxhighlight>
<syntaxhighlight lang="bash">xmlstarlet sel -t -v "count(/xml/table/rec/numField)" table.xml</syntaxhighlight>
Voir la [http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html documentation complète]
 
=== Exemple avancé ===
<syntaxhighlight lang="bash">
xmlstarlet sel -N xhtml="http://www.w3.org/1999/xhtml" -t -c "/xhtml:html/xhtml:head/xhtml:link" /tmp/bmo/bmoxml-basket.xml
</syntaxhighlight>
* {{cmd|sel}} : sélection de noeud dans le document XML ;
* {{cmd|-N xhtml&#61;"http://www.w3.org/1999/xhtml"}} : définition d'un espace de nom<ref>[http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html#d0e673 Namespaces and default namespace]</ref> ;
* {{cmd|-t -c "/xhtml:html/xhtml:head/xhtml:link"}} : le template XPath que l'on applique pour obtenir nos résultats<ref>[http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html#d0e270 Querying XML documents]</ref>.
** l'option {{cmd|-c}} ou {{cmd|--copy-of}} équivaut à un {{tag|xsl:copy-of}} ;
** l'option {{cmd|-v}} ou {{cmd|--value-of}} équivaut à un {{tag|xsl:value-of}}.
 
== Références ==
* [http://xmlstar.sourceforge.net/docs.php Quick help] XMLStarlet Command Line XML Toolkit
* [http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html Complete document as a single HTML page]
* [http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html#d0e270 Querying XML documents]
* [http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html#d0e673 Namespaces and default namespace]
<references/>


[[category:XML]]
[[category:XML]]
[[category:XPath]]
[[category:Doc]]
[[category:Doc]]
[[category:How To]]
[[category:How To]]

Version du 5 juillet 2012 à 09:11

GUI

Eclipse

On installera les plugins suivants qui sont disponible dans Eclipse Web Tools Platform :

  • XSL Tools SDK
    • PscyhoPath XPath 2.0 Processor Feature
    • XSL Tools Developer Resources

Remarques : On fera attention au processeur que l'on utilise : XPath 1.0 ou XPath 2.0.

Terminal

Utilitaire xpath

Cela correspond au paquet linux : libxml-xpath-perl disponible sur [[1]]

xpath -e '//archref/@href'

Pour n'avoir que les noeud, on rajoutera une redirection des erreurs à la fin de la commande : 2&>1

XMLStarlet

On peut également utiliser XMLStarlet, qui est open source, gratuit. Et disponible sur Windows et Linux.

xmlstarlet sel -t -v "count(/xml/table/rec/numField)" table.xml

Exemple avancé

xmlstarlet sel -N xhtml="http://www.w3.org/1999/xhtml" -t -c "/xhtml:html/xhtml:head/xhtml:link" /tmp/bmo/bmoxml-basket.xml
  • sel : sélection de noeud dans le document XML ;
  • -N xhtml="http://www.w3.org/1999/xhtml" : définition d'un espace de nom<ref>Namespaces and default namespace</ref> ;
  • -t -c "/xhtml:html/xhtml:head/xhtml:link" : le template XPath que l'on applique pour obtenir nos résultats<ref>Querying XML documents</ref>.
    • l'option -c ou --copy-of équivaut à un <xsl:copy-of> ;
    • l'option -v ou --value-of équivaut à un <xsl:value-of>.

Références

<references/>