Parameters.xml, XPath NamespacesRSS

1 reply

Last post Jul 03, 2013 01:09 PM by AEternal

  • Parameters.xml, XPath Namespaces

    Jul 07, 2009 10:56 AM|HarveyKandola|LINK

    We are using Parameters.xml file to capture SQL database credentials.

    We then update web.config file to reflect the new connection string:

       <parameterEntry
          type="XmlFile"
          scope="\\web.config$"
          match="//urn:hibernate-configuration/urn:session-factory/urn:property[@name='connection.connection_string']/text()" >
        </parameterEntry>

    The issue is that our our web.config connection string is located in a seperate namespace:

       <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">data source=localhost;initial catalog=Sample;user id=sa;password=xxx</property>
                <property name="generate_statistics">false</property>
        </session-factory>
        </hibernate-configuration>

    Hence the "match" must work on a namespace constraint XPath query.

    Any ideas? 

     

     

     

  • Re: Parameters.xml, XPath Namespaces

    Jul 03, 2013 01:09 PM|AEternal|LINK

    I had this exact issue. I found a solution - a combination of wildcards, local-name(), and namespace-uri(). It makes the string long, but it works.

    Using /*[local-name()='hibernate-configuration' and namespace-uri()='urn:nhibernate-configuration-2.2'] will identify the 'hibernate-configuration' at the root, and then you can navigate down from there using the same syntax, like so:

    /*[local-name()='hibernate-configuration' and namespace-uri()='urn:nhibernate-configuration-2.2']/*[local-name()='session-factory' and namespace-uri()='urn:nhibernate-configuration-2.2']//*[local-name()='property' and namespace-uri()='urn:nhibernate-configuration-2.2'][@name='connection.connection_string']/text()