NSIS XML更新(Wizou的插件)查询

时间:2016-01-30 07:40:40

标签: nsis

我正在尝试从xml文件中读取节点值并将其存储在变量中以将其放回另一个xml文件中。我在使用NSIS XML插件(By Wizou)的NSIS安装程序中执行此操作,我面临的问题是它没有读取节点值,我正在使用的代码如下,

nsisXML::create
nsisXML::load '${CONFIG}' /* This is the XML file for reading the value*/
messagebox MB_OK "Value in var0 is $0"
nsisXML::select '/hibernate-configuration/session-factory/property[@name="connection.connection_string"]'
messagebox MB_OK "Value in var1 is $1"
messagebox MB_OK "Value in var2 is $2"

在初始加载文件(文件存在于引用路径中)之后,我在$ 0中获得了一些值,这意味着xml文件正在加载,之后我正在尝试从它读取的位置选择节点值。但是在nsisxml :: select语句之后,var的$ 1和$ 2的值为0,这表明它找不到节点,但是当你查看它时它在xml中,XML文件内容如下,

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
DB String 
</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
</session-factory>
</hibernate-configuration>

知道我可能在哪里出错吗?提前谢谢

1 个答案:

答案 0 :(得分:1)

问题是您的XPath搜索字符串不处理xmlns。

你可以忽略这样的xmlns:

InitPluginsDir
FileOpen $0 "$pluginsdir\Test.xml" w
FileWrite $0 '<?xml version="1.0" encoding="utf-8" ?>$\r$\n'
FileWrite $0 '<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">$\r$\n'
FileWrite $0 '<session-factory>$\r$\n'
FileWrite $0 '<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>$\r$\n'
FileWrite $0 '<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>$\r$\n'
FileWrite $0 '<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>$\r$\n'
FileWrite $0 '<property name="connection.connection_string">DB String</property>$\r$\n'
FileWrite $0 `<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>$\r$\n`
FileWrite $0 '<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>$\r$\n'
FileWrite $0 '</session-factory>$\r$\n'
FileWrite $0 '</hibernate-configuration>$\r$\n'
FileClose $0

nsisXML::create
nsisXML::load "$pluginsdir\Test.xml"
DetailPrint doc=$0
nsisXML::select `/*[name()='hibernate-configuration']/*[name()='session-factory']/*[name()='property'][@name="connection.connection_string"]`
DetailPrint 1=$1,2=$2,3=$3