0

Trying to extract two strings of information from a xml file. In the example linkage.xml file, I'd like the batch file to run and create a directory Smith-John-yyyy-mm-dd. So far I am able to generate a folder with the date in the format I want (yyyy-mm-dd), but I am unable to extract "Smith" and "John" as variables. Help would be greatly appreciated.

linkage.xml

<LinkageParameter> 
   <Patient LastName="Smith" FirstName="John" ChartNumber="123">
      <Birthday>18/12/1972</Birthday>
      <Address>123 Main St, Salem, OR</Address>
      <ZipCode>97302</ZipCode>
      <Phone>(503)363-5432</Phone>
      <Mobile>(503)215-3215</Mobile>
      <SocialID>123456789</SocialID>
      <Gender>Male</Gender> 
   </Patient>
</LinkageParameter>

My folder.bat file

@echo off
for /f %%i in ('xml.exe sel -t -v "//LastName" CP.xml') do set var=%%i
for /f %%i in ('xml.exe sel -t -v "//LastName" CP.xml') do set var=%%j

setlocal enabledelayedexpansion

:: Extract date fields - language dependent
for /f "tokens=1-4 delims=/-. " %%i in ('date /t') do (
        set v1=%%i& set v2=%%j& set v3=%%k
        if "%%i:~0,1%%" gtr "9" (set v1=%%j& set v2=%%k& set v3=%%l)

        for /f "skip=1 tokens=2-4 delims=(-)" %%m in ('echo.^|date') do (
            set %%m=!v1!& set %%n=!v2!& set %%o=!v3!
    )
)

:: Final set for language independency (English and Portuguese - maybe works for Spanish and French)
set year=%yy%%aa%
set month=%mm%
set day=%dd%

md \\192.168.0.34\OpenDentImages\PatientImages\CT\%i%-%j%-%year%-%month%-%day%
1
  • 1
    Not sure where you got xml.exe from but Windows has native capability to read XML files with Vbscript and Jscript. Commented May 18, 2017 at 19:04

2 Answers 2

1

Instead of using xml.exe, and as long as the xml files are similar to that posted, you could try:

@Echo Off
Set "Pre="
For /F Tokens^=2^,4Delims^=^" %%A In ('Find "<Patient"^<"linkage.xml"'
) Do Set Pre=%%A-%%B
If Not Defined Pre GoTo :EOF

The variable %Pre% should in the case you've provided read Smith-John

Sign up to request clarification or add additional context in comments.

Comments

0

try with xpath.bat (no need to install external binaries):

for /f "tokens=* delims=" %%a in ('xpath.bat linkage.xml "//Patient/@LastName"') do set "last_name=%%~a"

for /f "tokens=* delims=" %%a in ('xpath.bat linkage.xml "//Patient/@FirstName"') do set "first_name=%%~a"

echo %first_name%    %last_name%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.