Search code examples
asp.netxmlnantibatis

How to poke connectionString in sqlmap.config?


In a similar way to what is done here, I would like to xmlpoke connectionString from an sqlmap.config file:

<?xml version="1.0" encoding="utf-8" ?>
<sqlMapConfig
   xmlns="http://ibatis.apache.org/dataMapper"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

    <database>
        <provider name="oracleClient1.0"/>
        <dataSource name="DSExtranetAdherent"
                    connectionString="Data Source=MyInstance;User ID=MyUser;Password=MyPwd;Unicode=True;"/>

    </database>

</sqlMapConfig>

I tried with this poke:

<xmlpoke
  file="${ConfigPath}\sqlmap.config"
  xpath="/sqlMapConfig/database/dataSource/@connectionString"
  value="${ConnectionString}" />

But I get an error message:

[xmlpoke] No matching nodes were found with XPath expression '/sqlMapConfig/database/dataSource/@connectionString'.

The xpath is effective when I remove the xmlns property, but then I get this runtime error:

Unable to load file via resource "SqlMap.config" as resource.

Any idea on how to fix this xmlpoke with a good xpath?


Solution

  • xmlns is the default namespace, xmlpoke require a prefix for xpath parsing:

    <xmlpoke
      file="${ConfigPath}\sqlmap.config"
      xpath="/iba:sqlMapConfig/iba:database/iba:dataSource/@connectionString"
      value="${ConnectionString}">
      <namespaces>
        <namespace prefix="iba" uri="http://ibatis.apache.org/dataMapper" />
      </namespaces>
    </xmlpoke>