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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Nodes

Status
Not open for further replies.

AHDV

MIS
Mar 1, 2002
2
GB
I am so very new with all this..........

We have an web based application that references data within XML data Island to populate pull down menus.
I need to be able to select data from within data island 1 - (Customers) based on a value within data island 2 - (Activities).

Data Island 1 - Activities

<XML ID="xmlAct">
<?xml version="1.0"?>
<activities>
<primary id="1" displaycode="Absence" customer="0" serial="0" bu="0" datevalidation="0">
<secondary activityid="121" lieutime="0">Bank Hol</secondary><secondary activityid="122" lieutime="0">Holiday</secondary>
<secondary activityid="126" lieutime="-1">Lieu</secondary>
</primary>
<primary id="2" displaycode="Admin" customer="0" serial="0" bu="0" datevalidation="0">
<secondary activityid="118" lieutime="0">Admin</secondary>
<secondary activityid="120" lieutime="0">Admin/Idle</secondary>
<secondary activityid="257" lieutime="0">BU Sfty</secondary>
<secondary activityid="426" lieutime="0">Int Mtg</secondary>
</primary>

Data Island 2 - Customers

<XML ID="xmlCust">
<?xml version="1.0"?>
<customers><customer id="12345" name="ABC">
<machine MachType="BB.123" delivery="36608" warrstart="36731" warrstartgap="36761" warrexpiry="37095" warrexpirygap="37125" syshandoff="36731" accept="36731">AA.12345</machine>
<machine MachType="AA.123" delivery="36670" warrstart="36845" warrstartgap="36875" warrexpiry="37210" warrexpirygap="37240" syshandoff="36845" accept="36845">AA.12341</machine>
<machine MachType="AA.321" delivery="36675" warrstart="36814" warrstartgap="36844" warrexpiry="37179" warrexpirygap="37209" syshandoff="36814" accept="36814">AA.12342</machine>
</customer>
</customers>

Problem

I need to say where id = 1 within xmlAct then only select attributes within xmlcust that have a MachType value of '*.123'

If I have been at all vague (which I know I have been but thats because I haven't got a clue what I'm talking about then please let me know)

This has now become an urgent issue and I desperately need some help.

Thanks ever so much
 
I need to say where id = 1 within xmlAct then only select attributes within xmlcust that have a MachType value of '*.123'
You need to explain this better, as it makes no sense.


Jon

"I don't regret this, but I both rue and lament it.
 
I can show you (op) how to do thing of the sort. It contains all the necessary elements for such kind of construction. It is in a sense pretty involved to explain in word. I do it in vbs in this demo. You can translate it into js. The target user's agent is sure msie.
[tt]
<html>
<head>
<script language="vbscript">
sub buildselactivity
dim oelem,obj,squery,oxml,cnodes,onode
set oelem=document.formname.selactivity
squery="/activities/primary/secondary"
set oxml=document.getElementById("xmlAct")
set cnodes=oxml.selectNodes(squery)
for each onode in cnodes
set obj=document.createElement("option")
obj.text=onode.text
obj.value=onode.getAttribute("activityid")
oelem.options.add obj
set obj=nothing
next
set cnodes=nothing
set oxml=nothing
end sub
sub buildselcustomer(v)
dim oelem,obj,squery,oxml,cnodes,onode,vid
set oelem=document.formname.selcustomer
oelem.length=0 'rebuilt
set obj=document.createElement("option")
obj.text="choose a customer-machine"
obj.value="void"
oelem.options.add obj
set obj=nothing
set oxml=document.getElementById("xmlAct")
set cnodes=oxml.selectNodes("/activities/primary/secondary")
for each onode in cnodes
if onode.getAttribute("activityid")=v then
vid=onode.parentNode.getAttribute("id")
exit for
end if
next
set oxml=nothing
set cnodes=nothing
set oxml=document.getElementById("xmlCust")
squery="/customers/customer/machine"
set cnodes=oxml.selectNodes(squery)
for each onode in cnodes
select case vid
case 1
if split(onode.getAttribute("MachType"),".")(1)="123" then
set obj=document.createElement("option")
obj.text=onode.text
obj.value=onode.getAttribute("MachType")
oelem.options.add obj
set obj=nothing
end if
case 2
if split(onode.getAttribute("MachType"),".")(1)<>"123" then
set obj=document.createElement("option")
obj.text=onode.text
obj.value=onode.getAttribute("MachType")
oelem.options.add obj
set obj=nothing
end if
case else
'do nothing
end select
next
set cnodes=nothing
set oxml=nothing
end sub
window.onload=getref("buildselactivity")
</script>
</head>
<body>
<XML ID="xmlAct">
<?xml version="1.0"?>
<activities>
<primary id="1" displaycode="Absence" customer="0" serial="0" bu="0" datevalidation="0">
<secondary activityid="121" lieutime="0">Bank Hol</secondary>
<secondary activityid="122" lieutime="0">Holiday</secondary>
<secondary activityid="126" lieutime="-1">Lieu</secondary>
</primary>
<primary id="2" displaycode="Admin" customer="0" serial="0" bu="0" datevalidation="0">
<secondary activityid="118" lieutime="0">Admin</secondary>
<secondary activityid="120" lieutime="0">Admin/Idle</secondary>
<secondary activityid="257" lieutime="0">BU Sfty</secondary>
<secondary activityid="426" lieutime="0">Int Mtg</secondary>
</primary>
</activities>
</XML>
<XML ID="xmlCust">
<?xml version="1.0"?>
<customers>
<customer id="12345" name="ABC">
<machine MachType="BB.123" delivery="36608" warrstart="36731" warrstartgap="36761" warrexpiry="37095" warrexpirygap="37125" syshandoff="36731" accept="36731">AA.12345</machine>
<machine MachType="AA.123" delivery="36670" warrstart="36845" warrstartgap="36875" warrexpiry="37210" warrexpirygap="37240" syshandoff="36845" accept="36845">AA.12341</machine>
<machine MachType="AA.321" delivery="36675" warrstart="36814" warrstartgap="36844" warrexpiry="37179" warrexpirygap="37209" syshandoff="36814" accept="36814">AA.12342</machine>
</customer>
</customers>
</XML>
<form name="formname">
<select name="selactivity" onchange="msgbox me.value : buildselcustomer me.value">
<option value="void">choose an activity</option>
</select>
<select name="selcustomer" onchange="msgbox me.value">
<option value="void">choose a customer-machine</option>
</select>
</form>
</body>
</html>
[/tt]
Here the use of xpath is loose and can certainly be tightened up a bit more. It leasves however enough space for added filtering. The msgbox in the onchange handler is to show you sensible result is obtained. Feel free to take them out after testing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top