@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,556
167
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
12,165
133
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,556
167
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
12,165
133
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