@XMLXPATH not working in v28

Jun 6, 2009
26
0
I have a sample file source.xml:

XML:
<?xml version="1.0" encoding="UTF-8"?>
<Instructors>
    <Instructor Dept_ID="123">
       <Name First="John" Last="Doe">Doe, John</Name>
    </Instructor>
    <Instructor Dept_ID="456">
       <Name First="Jane" Last="Doe">Doe, Jane</Name>
    </Instructor>
</Instructors>

and batch file test.btm.
Code:
@echo off

SET a=%@XMLOPEN[source.xml]
SET b=%@XMLNODES[/Instructors]      

DO i = 1 to %b
  SET id=%@XMLXPATH[/Instructors/Instructor[%i]/@Dept_ID]
  echo %id
ENDDO

SET c=%@XMLCLOSE[]

As expected, the script returns
Code:
123
456

from TCC 26.02.43 x64 on Windows 10. However, the script fails with the following error when run from TTC 27.01.24 x64 or TCC 28.01.14 x64.
Code:
TCC: C:\Users\rhens\OneDrive - Michigan State University\Department Queries\MailMerge\scratch\test.btm [9]  Invalid XPath. "/Instructors/Instructor[1]/@Dept_
ID"
ECHO is OFF
TCC: C:\Users\rhens\OneDrive - Michigan State University\Department Queries\MailMerge\scratch\test.btm [9]  Invalid XPath. "/Instructors/Instructor[2]/@Dept_
ID"
ECHO is OFF

Am I doing something wrong?
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
Vv26 was using an old/obsolete/deprecated Windows xml parser), and only had 4 XML functions. V27 / 28 added 17 more XML functions, so some of the kludges in v26 were replaced by separate function calls.

In v28, you would do that this way:

Code:
@echo off

SET a=%@XMLOPEN[source.xml]
SET b=%@XMLNODES[/Instructors]      

DO i = 1 to %b
  SET xpath=%@XMLXPATH[/Instructors/Instructor[%i]]
  SET id=%@XMLGETATTR[Dept_ID]
  echo %id
ENDDO

SET c=%@XMLCLOSE[]
 
May 20, 2008
11,529
102
Syracuse, NY, USA
Vv26 was using an old/obsolete/deprecated Windows xml parser), and only had 4 XML functions. V27 / 28 added 17 more XML functions, so some of the kludges in v26 were replaced by separate function calls.

In v28, you would do that this way:

Code:
@echo off

SET a=%@XMLOPEN[source.xml]
SET b=%@XMLNODES[/Instructors]     

DO i = 1 to %b
  SET xpath=%@XMLXPATH[/Instructors/Instructor[%i]]
  SET id=%@XMLGETATTR[Dept_ID]
  echo %id
ENDDO

SET c=%@XMLCLOSE[]
How do you do it with a filename? I tried this.

Code:
SET file="v:\source.xml"
SET b=%@XMLNODES[%file,/Instructors]      

DO i = 1 to %b
  SET xpath=%@XMLXPATH[%file,/Instructors/Instructor[%i]]
  SET id=%@XMLGETATTR[%file,Dept_ID]
  echo %id
ENDDO
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
How do you do it with a filename? I tried this.

Code:
SET file="v:\source.xml"
SET b=%@XMLNODES[%file,/Instructors]     

DO i = 1 to %b
  SET xpath=%@XMLXPATH[%file,/Instructors/Instructor[%i]]
  SET id=%@XMLGETATTR[%file,Dept_ID]
  echo %id
ENDDO

Why would you want to?

There isn't any xpath (since you did your @xmlxpath with a filename, it wasn't persisted), so it's going to use the default.
 
May 20, 2008
11,529
102
Syracuse, NY, USA
Why would you want to?

It doesn't seem like you can process two (or more) files at once using @XMLOPEN? I don't need to do that but it seems reasonable if one wanted to compare of merge two of them. I only tried it out of curiosity.
 
Similar threads
Thread starter Title Forum Replies Date
mikea How to? TCC and XMLnodes/XMLxpath functions Support 0
P PSHELL not working in TCC 26 Support 9
twaterloo FolderMonitor for the 1st time not working Support 5
Tim Rowe NTFS Descriptions not working Support 13
J Batcomp still not working for me in TCMD27 Support 1
M Oracle batch OPatch.bat.bat not working in TCC but correctly in CMD Support 5
M Why did BEEP just quit working? Support 12
cgunhouse SETLOCAL not working in BDEBUGGER Support 9
nickles ANSI Colors Windows 7 no longer working Support 6
K ANSI Not Working Support 8
thorntonpg option /u not working The directory name is invalid Support 5
Charles Dye Is the "File Associations" installer dialog working? Support 4
H @ceiling @floor @int not working version 21.01.63 Support 9
K Command Line Selection Not Working Support 12
G Extended directory search not working Support 4
B %@fileseek is not working ? Support 2
C "Take Command has stopped working" Support 1
H New command not working well in Windows 7 Support 4
C "TakeCommand has stopped working" Support 3
N ping DNS lookup not working Support 1
N Updater/silentall not working? Support 1
K Help Not Working Support 11
R Fixed set /r has stopped working in build 35 Support 4
U Keys and IDX not working Support 11
Jesse Heines How to? Everything Tool Not Working After Version 20 Installation Support 8
WavSlave Fixed LIST /U not working in TCC v19 Support 5
Jay Sage %_selected no longer working Support 15
S iftp copying pgp files from ftp is not working Support 11
fishman@panix.com Extended Directory Searches are not working for me in CDD Support 9
J How to set working directory Support 10
vefatica Fixed LEAVE N not working Support 7
P %date5 not working Support 6
M WAD PDir not working correctly... Support 5
Detlef Fixed ParameterChar in TCMD.INI no longer working Support 35
Jay Sage WAD Variable _LOGFILE Not Working Support 2
I v16 - Shortcuts not working Support 6
rps Fixed Win "set /p" not working in V17 build 53 Support 3
Jay Sage Toolbar Update to INI File Not Working Support 10
Jay Sage Ctrl-C Not Working Reliably to Copy Screen Content Support 4
Jay Sage Unknown_CMD Not Working Support 4
fromano Fixed /E not working in TCMD 17.0.40 while doing one way synch Support 1
R WAD Copy's command dialogue not working Support 2
C WAD @index not working in v16 x64 Support 14
Dan Glynhampton Fixed @version "force" flag not working, and unable to set separator Support 3
C RSS feed subscription not working Support 9
M @Index not working like I thought it would... Support 2
C Working with links Support 6
C Move /MD not always working Support 1
C Startup folder not working on v15 Support 6
T Documentation Comspec not working Support 3

Similar threads