1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trying to read XML

Discussion in 'Support' started by MickeyF, Feb 7, 2014.

  1. MickeyF

    Joined:
    Jun 3, 2008
    Messages:
    74
    Likes Received:
    0
    I'm really weak at XML. OK, given that, I'm trying to write a simple script that will read an XML-formatted file and produce a value out of it. Here is a subset of the sample XML file:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <?xml-stylesheet type="text/xsl" href="is.xsl" ?>
    <!DOCTYPE msi [
       <!ELEMENT msi   (summary,table*)>
       <!ATTLIST msi version    CDATA #REQUIRED>
    ]>
    <msi version="2.0" xmlns:dt="urn:schemas-microsoft-com:datatypes" codepage="65001">
      <summary>
        <codepage>1252</codepage>
        <title>Installation Database</title>
      </summary>
      <table name="InstallShield">
        <col key="yes" def="s72">Property</col>
        <col def="S0">Value</col>
        <row><td>ActiveLanguage</td><td>1033</td></row>
        <row><td>SchemaVersion</td><td>774</td></row>
        <row><td>Type</td><td>MSI</td></row>
      </table>
    </msi>
    Here is my ill-fated attempt at reading the SchemaVersion value (for which I want the end result of this batch file to set the _InstallShieldSchema variable to 774):

    Code:
    set _InstallShieldSchema=%@XMLXPath["Aurora.ism","//msi/table[@name='InstallShield']/SchemaVersion"]
    echo SchemaVersion is %_InstallShieldSchema
    When I run this, I get an error: "TCMD: (XML) Line: 3; Char: 11 DTD is prohibited."
     
  2. MickeyF

    Joined:
    Jun 3, 2008
    Messages:
    74
    Likes Received:
    0
    Anyone? Anyone? Bueller?
     
  3. Dave Keyes

    Joined:
    Sep 11, 2013
    Messages:
    1
    Likes Received:
    0
    I had to comment out the DOCTYPE block to get rid of the error you are seeing. Here is the script that I came up with to get what you are wanting:

    Comment out the block in the XML file:

    <!-- <!DOCTYPE msi [
    <!ELEMENT msi (summary,table*)>
    <!ATTLIST msi version CDATA #REQUIRED>
    ]> -->

    Script code:

    @echo off
    SET a=%@XMLOPEN[Test.xml]
    SET b=%@XMLNODES[//msi/table[@name='InstallShield']/row]
    DO i = 2 to %b
    SET c=%@XMLNODES[//msi/table[@name='InstallShield']/row/td]
    DO j = 2 to %c
    set _InstallShieldSchema=%@XMLXPath[//msi/table[@name='InstallShield']/row[%i]/td[%j]]
    ENDDO
    ENDDO
    @echo SchemaVersion is %_InstallShieldSchema
    SET d=%@XMLCLOSE[]
     
  4. MickeyF

    Joined:
    Jun 3, 2008
    Messages:
    74
    Likes Received:
    0
    Thank you for the attempt, Dave, but I can't remove the DOCTYPE block. It's part of the file I have to process, with no option otherwise.

    OK, I solved this problem with a completely different approach. Not a very flexible solution, but it does the job. I know that SchemaVersion is unique within the file, and the format of the line where it is found doesn't change (at least not now, and not in all of the previous versions to which I have access).

    GetISSchemaVersion.btm:

    Code:
    setlocal
    setdos /x-6
    set _ism=%@MaybeQuote[%@full[%@expand[*.ism]]]
    rem Line containing schema looks like:
    rem  <row><td>SchemaVersion</td><td>774</td></row>
    set _Ver=%@execstr[*grep SchemaVersion %_ism]
    set _Index=%@eval[%@index[%_Ver,/td] + 8]
    echo SchemaVersion is %@instr[%_Index,3,%_ver]
    setdos /x+6
    rem If you want just the number, use %@word[-0,[%@execstr[getisschemaversion]]
    endlocal
    (edited to put the * in front of grep, since I have an alias for grep to call grep in a special way, but in this instance I just want to call the regular program)
     
    #4 MickeyF, Feb 13, 2014
    Last edited: Feb 13, 2014

Share This Page