Extracts text from an XML file at the location specified by an XPath
expression.
If the XPath expression specifies multiple nodes the node index is used to determine which of the nodes' text is returned.
Parameters
Attribute | Type | Description | Required |
---|---|---|---|
property | string |
The property that receives the text representation of the XML inside
the node returned from the XPath expression.
|
True |
file | file |
The name of the file that contains the XML document
that is going to be peeked at.
|
True |
xpath | string |
The XPath expression used to select which node to read.
|
True |
nodeindex | int |
The index of the node that gets its text returned when the query
returns multiple nodes.
|
False |
failonerror | bool |
Determines if task failure stops the build, or is just reported.
The default is
true .
|
False |
if | bool |
If
true then the task will be executed; otherwise,
skipped. The default is true .
|
False |
unless | bool |
Opposite of
NAnt.Core.Task.IfDefined . If false
then the task will be executed; otherwise, skipped. The default is
false .
|
False |
verbose | bool |
Determines whether the task should report detailed build log messages.
The default is
false .
|
False |
Nested elements
<namespaces>
Namespace definitions to resolve prefixes in the XPath expression.
Parameters
Attribute | Type | Description | Required |
---|---|---|---|
prefix | string |
The prefix to associate with the namespace.
|
True |
uri | string |
The associated XML namespace URI.
|
True |
if | bool |
Indicates if the namespace should be added to the
System.Xml.XmlNamespaceManager .
If true then the namespace will be added;
otherwise, skipped. The default is true .
|
False |
unless | bool |
Indicates if the namespace should not be added to the
System.Xml.XmlNamespaceManager .
list. If false then the parameter will be
added; otherwise, skipped. The default is false .
|
False |
<namespaces>
Examples
The example provided assumes that the following XML file (App.config) exists in the current build directory.
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="http://www.gordic.cz/shared/project-config/v_1.0.0.0">
<appSettings>
<add key="server" value="testhost.somecompany.com" />
</appSettings>
</configuration>
The example will read the server value from the above configuration file.
NOTE: The example below shows that the default namespace needs to also be declared. Simply set any prefix and use that prefix in the xpath.
<xmlpeek
file="App.config"
xpath="/x:configuration/x:appSettings/x:add[@key = 'server']/@value"
property="configuration.server">
<namespaces>
<namespace prefix="x" uri="http://www.gordic.cz/shared/project-config/v_1.0.0.0" />
</namespaces>
</xmlpeek>
Requirements
- Assembly
- NAnt
.Core .dll - Namespace
-
NAnt
.Core .Tasks