Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 889 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to select specific child nodes, having particular attribute value, using the parent node object, using XML query in JScript?

#1
My XML:
<tests>
<test name="Machine1" enabled="true">
<action enabled="true" Result="true">T_1</action>
<action enabled="true" Result="false">T_2</action>
<action enabled="true" Result="true">T_3</action>
<action enabled="true" Result="none">T_4</action>
</test>
<test name="Machine2" enabled="false">
<action enabled="true" Result="true">T_5</action>
<action enabled="true" Result="false">T_6</action>
<action enabled="true" Result="false">T_7</action>
<action enabled="true" Result="true">T_8</action>
</test>
</tests>

I want to select child nodes having, attribute [@Result='true'] from the "test" node having attribute [@enabled='true'].
i.e ideally it should give two nodes:

<action enabled="true" Result="true">T_1</action>
<action enabled="true" Result="true">T_3</action>

Instead I am getting all nodes from the entire xml having attribute [@Result='true']. i.e:

<action enabled="true" Result="true">T_1</action>
<action enabled="true" Result="true">T_3</action>
<action enabled="true" Result="true">T_5</action>
<action enabled="true" Result="true">T_8</action>

My Code:

var filepath = "C:\\Test.xml"
var oXML = Runner.CallMethod("XMLLib.LoadDOM", filepath);
var testNodes = oXML.SelectNodes("//test");
for (var i=0; i<testNodes.length; i++)
{
var test = testNodes.nextNode;
if (test.getAttribute("enabled") == "true")
{
var pass = test.SelectNodes("//action[@Result='true']").length;
var fail = test.SelectNodes("//action[@Result='false']").length;
var missing = test.SelectNodes("//action[@Result='none']").length;
}
}

Please help me with the solution Or any other way to get the desired result...Thanks!
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through