computing
  • 2

Solved Batch File To Read Some Data From XML.

  • 2

I’m trying to make a batch file to pull data out of a file and set it as a variable.

The tricky part is I need to read a XML file, and I only need the data between the quotes of the following line…

narrative=”I only need this text here”

The text in that line can also contain spaces, brackets, slashes, dashes and colons.

Share

1 Answer

  1. Yeh, batch can be kind of lame handling xml, but in this case, it seems like it should have worked since findstr was doing the heavy lifting, leaving batch only handling that one line. You might examine your xml file to see what kind of line-breaks it’s using – maybe it’s cr with no lf. You can use debug or edit /80 to see what it’s using.
    OR, as per Razor’s suggestion, vbscript (or another language) could do a readall and probably solve the problem:
    ‘==== begin vbscript “xmlfind”
    if wscript.arguments.count<1 then
    wscript.echo “Usage: XMLFIND file.xml targetstring”
    wscript.quit
    end if
    targ=wscript.arguments(1)
    set fso=createobject(“scripting.filesystemobject”)
    set test=fso.opentextfile(wscript.arguments(0),1)
    z=test.readall
    ‘remove lcase() from foll line to observe case in search
    point1=instr(lcase(z),lcase(targ))
    if point1=0 then
    wscript.echo “NOT FOUND: string: “&targ;
    wscript.quit
    end if
    point1=point1+len(targ)
    found=ltrim(mid(z,point1))
    quote=left(found,1)
    found=mid(found,2)
    point2=instr(found,quote)
    if point2>0 then
    found=left(found,point2-1)
    end if
    wscript.echo chr(34)&found;&chr;(34)
    ‘===== end vbscript
    • 0