开发者

XPath Specific Question, Selecting a child given value of another child

I need to retrieve all of these types of nodes: <parameter value="thisisthename" name="parameters" /> where type = MyTest and one of the child <parameter value="c:\temp\svn.exe" name="file" /> equals c:\temp\svn.exe

Right now I have

ert[type='MyTest']/parameters/parameter[@value='c:\temp\svn.exe']

  <ert agents="0031">
  <type>MyTest</type> 
  <parameters>
  <parameter value="c:\temp\svn.exe" name="file" /> 
  <parameter value="thisisthename开发者_开发知识库" name="parameters" /> 
  <parameter value="200" name="count" /> 
  </parameters>
  </ert>


You are almost there. This is the XPath expression you're looking for:

/ert[type='MyTest']/parameters/parameter[@value='c:\temp\svn.exe']/../parameter[@value='thisisthename']

The idea is that you can move up the xml tree using /...

If you happen to know that c:\temp\svn.exe is always somewhere before the parameter node you want, you could also use:

/ert[type='MyTest']/parameters/parameter[@value='c:\temp\svn.exe']/following-sibling::parameter[@value='thisisthename']

This may be a little faster since no backtracking will occur.


I go back to this site whenever I have XPath questions...hopefully it helps you.

http://www.w3schools.com/XPath/xpath_syntax.asp


I need to retrieve all of these types of nodes: <parameter value="thisisthename" name="parameters" /> where type = MyTest and one of the child <parameter value="c:\temp\svn.exe" name="file" /> equals c:\temp\svn.exe

All this three conditions, in Xpath:

/ert[type='MyTest']
    [parameters/parameter[@value='c:\temp\svn.exe']]
    /parameters/parameter[@value][@name]

This means: from an ert root element having a type child with "MyTest" string value and a parameters/parameter grandchild with value attribute equal to "c:\temp\svn.exe", I want all parameters/parameter grandchidren having value and name attributes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜