Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Node from XML - not working :O(

Status
Not open for further replies.

MrPeds

Programmer
Jan 7, 2003
219
GB
Hi,

I have the following XML fragment that I am trying to get information from using MS xml dom in Javascript methods:

<Goals>
<Goal id="123">

<someELement1/>
<someElement2/>
<myTargets myAttr1="567" myAttr2="909">

<myTarget>
<myTargetID>21</myTargetID>
<myTargetElement1>dfg</myTargetElement1>
<myTargetElement2>wpoerw</myTargetElement2>
</myTarget>

<myTarget>
<myTargetID>22</myTargetID>
<myTargetElement1>qwerqwe</myTargetElement1>
<myTargetElement2>zxcv</myTargetElement2>
</myTarget>


</myTargets>



</Goal>
</Goals>

Each Goal id is unique, and similalry each myTargetID is unique.

I am trying to get the element myTarget, for the specified goalid, and the specified value of myTargetID. So, for example if I give the goal id of 123, and the value myTargetID = 22 I would be given this element:

<myTarget>
<myTargetID>21</myTargetID>
<myTargetElement1>dfg</myTargetElement1>
<myTargetElement2>wpoerw</myTargetElement2>
</myTarget>

I've tried doing selectSingleNode, and so on, can anybody see what i need to do to achieve this, I've tried stuff like this:

var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
strXML = document.getElementById('txtGoalInformation').value ;
xmlDoc.loadXML(strXML) ;

//Get the document element
var oRoot = xmlDoc.documentElement ;

strXPath = "Goals/Goal[@id='" + iGoalID + "']/MetricResults/MetricResult[myTargetID='21']";

var oResultNode = oRoot.selectSingleNode(strXPath) ;
var oParentNode = oResultNode.parentNode ;


Any suggestions are appreciated.

Thanks,

MrPeds



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top