#136 xmlpeek with count() fails

closed-fixed
Tasks (82)
5
2010-05-23
2006-09-18
No

The task <xmlpeek> does not work with the xpath count
() function:

e.g.

<xmlpeek file="autotest.xml" xpath="count
(/Autotester/Script/Message[@Level='Error'])"
property="errorcount" />

ALWAYS fails with the following message:

Failed to select node with XPath expression 'count
(/Autotester/Script/Message[@Level='Error'])'.
The expression passed to this method should result
in a NodeSet.

The file autotest.xml looks like that:

<Autotester Type="Errorlog">
<Script Name="Autotest.tst">
<Message Level="Error" Nr="1" Event="Begin" />
</Script>
</Autotester>

-
Gerald

Discussion

  • Rob M

    Rob M - 2007-04-16

    Logged In: YES
    user_id=1771101
    Originator: NO

    I am also unable to get xmlpeek to work with the count function.

     
  • Charles Chan

    Charles Chan - 2010-02-16

    Does this affect xpath count() only? What about other functions such as exists() or string-length()?

    If it only affect certain functions only, then it is truly odd.

     
  • Charles Chan

    Charles Chan - 2010-02-18
    • assigned_to: nobody --> cchan_qa
     
  • Charles Chan

    Charles Chan - 2010-02-20

    The problem is in XmlPeekTask.cs. Specifically in GetNodeContents(), it is using

    nodes = document.SelectNodes(xpath, nsMgr);

    Referring to MSDN, SelectNodes() specifically returns a XmlNodeList and using count() is invalid.

     
  • Charles Chan

    Charles Chan - 2010-02-20
    • labels: 347142 --> Tasks
    • milestone: 359426 -->
     
  • Charles Chan

    Charles Chan - 2010-02-20

    Referring to the NAnt documentation for <xmlpeek>

    "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."

    So I think the current behavior is correct, so I am changing this from a bug to a feature request.

     
  • Charles Chan

    Charles Chan - 2010-02-20

    To support this feature would require changing the internal implementation from using a XmlDocument.SelectNodes() to XPathNavigator.Evaluate() method.

    XPathNavigator.Evaluate() returns and Object. The result of the expression (Boolean, number, string, or node set). This maps to Boolean, Double, String, or XPathNodeIterator objects respectively.

    I have to try this first, but in theory, this should support the previous functionality and should extend to the new request.

     
  • Charles Chan

    Charles Chan - 2010-05-23

    This should work now. I expanded the <xmlpeek> task and could use some additional advance xpath functions/syntax properly now.

    <?xml version="1.0"?>
    <project name="Hello World">
    <xmlpeek file="autotest.xml" xpath="boolean(count(/Autotester/Script/Message[@Level='Error']) = 3)"
    property="errorcount" />
    <echo message="${errorcount}" />

    <xmlpeek file="autotest.xml" xpath="/Autotester/Script/Message"
    property="xpathvalue" />
    <echo message="${xpathvalue}" />

    <xmlpeek file="autotest.xml" xpath="/Autotester/Script/Message"
    property="xpathvalue" nodeindex="2" verbose="true"/>
    <echo message="${xpathvalue}" />

    <xmlpeek file="autotest.xml" xpath="/Autotester/Script/Message[1]"
    property="errorcount" />
    <echo message="${errorcount}" />

    <xmlpeek file="autotest.xml" xpath="/Autotester/Script/Message[@Level='Error'][2]/@Event"
    property="errorcount" verbose="true" />
    <echo message="${errorcount}" />
    </project>

     
  • Charles Chan

    Charles Chan - 2010-05-23
    • status: open --> closed-fixed
     
  • Charles Chan

    Charles Chan - 2010-05-23

    Resolved Fixed. This is now checked into the CVS head.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks