Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for readxml.bat

(view source code of readxml.bat as plain text)

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. SETLOCAL
  6. :: Check command line
  7. IF     "%~1"=="" GOTO Syntax
  8. IF NOT "%~4"=="" GOTO Syntax
  9. IF NOT "%~3"=="" IF /I NOT "%~3"=="/T" GOTO Syntax
  10. ECHO "%~1" | FIND "/" >NUL || GOTO Syntax
  11. ECHO "%~2" | FIND "/" >NUL && GOTO Syntax
  12. IF /I "%~3"=="/T" (SET Format=-T) ELSE (SET Format=-D)
  13. IF NOT EXIST "%~f2" GOTO Syntax
  14.  
  15. :: Check if XML Starlet is available
  16. XML.EXE --version >NUL 2>&1 || GOTO Syntax
  17.  
  18. :: Use XML Starlet to return handle the query
  19. XML.EXE sel -R %Format% -t -c "%~1" "%~2"
  20.  
  21. ENDLOCAL
  22. GOTO:EOF
  23.  
  24.  
  25. :Syntax
  26. ECHO.
  27. ECHO ReadXML.bat,  Version 1.10
  28. ECHO Read the specified value from the specified XML file
  29. ECHO.
  30. ECHO Usage:  %~n0  "xpath_expression"  "xml_file"  [ /T ]
  31. ECHO.
  32. ECHO Where:  "xpath_expression" is the XPATH expression to get the requested value
  33. ECHO         "xml_file"         is the XML file to search
  34. ECHO         /T                 output as text (default: XML)
  35. ECHO.
  36. ECHO Note:   Requires XML Starlet, available at http://xmlstar.sourceforge.net/
  37. ECHO.
  38. ECHO Written by Rob van der Woude
  39. ECHO http://www.robvanderwoude.com
  40.  
  41. IF "%OS%"=="Windows_NT" ENDLOCAL & COLOR 00
  42.  

page last uploaded: 2017-07-06, 12:37