Created
February 12, 2014 02:24
-
-
Save hell0again/8948854 to your computer and use it in GitHub Desktop.
xmllintとxpathのテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FILE=test.xml | |
EXPR="string(/node/node/@*[local-name()='key'])" | |
echo '[prepare1. xmllint --version]' | |
echo $( xmllint --version ) | |
echo "" | |
echo "" | |
echo '[prepare2. xpath]' | |
echo $( xpath ) | |
echo "" | |
echo "" | |
echo '[case1. echo "xpath ${EXPR}" | xmllint --shell ${FILE} ]' | |
RES=$( echo "xpath ${EXPR}" | xmllint --shell ${FILE} 2>/dev/null ) | |
if [ $(echo "${RES}" | head -c 1) = "/" ]; then | |
echo "${RES}" | awk '($1 == "Object"){print $6}' | |
else | |
echo "${RES}" | |
fi | |
echo "" | |
echo "" | |
echo '[case2. xmllint --xpath ${EXPR} ${FILE} ]' | |
xmllint --xpath "${EXPR}" ${FILE} 2>/dev/null | |
echo "" | |
echo "" | |
echo '[case3. xpath -e ${EXPR} ${FILE} ]' | |
xpath -e "${EXPR}" ${FILE} 2>/dev/null | |
echo "" | |
echo "" | |
echo '[case4. xpath ${FILE} ${EXPR} ]' | |
xpath ${FILE} "${EXPR}" 2>/dev/null | |
echo "" | |
echo "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<node> | |
<node key="123456789012345678901234567890123456789012345678901234567890E"/> | |
<hoge>gege</hoge> | |
</node> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[prepare1. xmllint --version] | |
xmllint: using libxml version 20800 | |
compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma | |
[prepare2. xpath] | |
Usage: | |
/usr/bin/xpath [options] -e query [-e query...] [filename...] | |
If no filenams are given, supply XML on STDIN. | |
You must provide at least one query. Each supplementary | |
query is done in order, the previous query giving the | |
context of the next one. | |
Options: | |
-q quiet. Only output the resulting PATH | |
-s suffix use suffix instead of linefeed. | |
-p postfix use prefix instead of nothing. | |
[case1. echo "xpath ${EXPR}" | xmllint --shell ${FILE} ] | |
1234567890123456789012345678901234567890... | |
[case2. xmllint --xpath ${EXPR} ${FILE} ] | |
123456789012345678901234567890123456789012345678901234567890E | |
[case3. xpath -e ${EXPR} ${FILE} ] | |
123456789012345678901234567890123456789012345678901234567890E | |
[case4. xpath ${FILE} ${EXPR} ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment