NAnt SDK Documentation - v0.85-nightly-2005-11-09

XmlPokeTask Class

[This is preliminary documentation and subject to change.]

Replaces text in an XML file at the location specified by an XPath expression.

For a list of all members of this type, see XmlPokeTask Members.

System.Object
   NAnt.Core.Element
      NAnt.Core.Task
         NAnt.Core.Tasks.XmlPokeTask

[Visual Basic]
<TaskName(Name:="xmlpoke")>
Public Class XmlPokeTask
    Inherits Task
[C#]
[TaskName(Name="xmlpoke")]
public class XmlPokeTask : Task

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

The location specified by the XPath expression must exist, it will not create the parent elements for you. However, provided you have a root element you could use a series of the tasks to build the XML file up if necessary.

Example

Change the server setting in the configuration from testhost.somecompany.com to productionhost.somecompany.com.

XML file:

                
            <?xml version="1.0" encoding="utf-8" ?>
            <configuration>
                <appSettings>
                    <add key="server" value="testhost.somecompany.com" />
                </appSettings>
            </configuration>
                
              

Build fragment:

                
            <xmlpoke
                file="App.config"
                xpath="/configuration/appSettings/add[@key = 'server']/@value"
                value="productionhost.somecompany.com" />
                
              

Modify the noNamespaceSchemaLocation in an XML file.

XML file:

                
            <?xml version="1.0" encoding="utf-8" ?>
            <Commands xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Path Value">
            </Commands>
                
              

Build fragment:

                
            <xmlpoke file="test.xml" xpath="/Commands/@xsi:noNamespaceSchemaLocation" value="d:\Commands.xsd">
                <namespaces>
                    <namespace prefix="xsi" uri="http://www.w3.org/2001/XMLSchema-instance" />
                </namespaces>
            </xmlpoke>
                
              

Requirements

Namespace: NAnt.Core.Tasks

Assembly: NAnt.Core (in NAnt.Core.dll)

See Also

XmlPokeTask Members | NAnt.Core.Tasks Namespace