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

How i can assign variables to values in a xmlstring? 1

Status
Not open for further replies.

manvee1

Programmer
Jul 17, 2002
22
US
I have a sorce doc as the xmlstring below and i am trying to assign varables to the values in the xmlstring.

problem is that the varables are returning as nothing.
i.e: the expression 'var_for_DocNo = currAttr.Text' should be "123" but its comming up as nothing

any ideas on how i can bind these variables?
or do u need more info?


below is the xmlstring:
<Parameter><DocNo>VALUE=&quot;123&quot;</DocNo><Type>VALUE=&quot;A&quot;</Type><Day>VALUE=&quot;Mon&quot;</Day></Parameter>
<Parameter><DocNo>VALUE=&quot;111&quot;</DocNo><Type>VALUE=&quot;C&quot;</Type><Day>VALUE=&quot;Tue&quot;</Day></Parameter>
<Parameter><DocNo>VALUE=&quot;333&quot;</DocNo><Type>VALUE=&quot;D&quot;</Type><Day>VALUE=&quot;Wed&quot;</Day></Parameter>

************************************************************
This is how im trying to assign the values after creating a list of parameter nodes:-

Set nodList = anXMLDoc.selectNodes(&quot;*//Parameter&quot;)
For Each Nod In nodList

Set Nod = anXMLDoc.selectSingleNode(&quot;//Doc_No&quot;)
Set Attr = Nod.Attributes.getNamedItem(&quot;VALUE&quot;)
var_for_DocNo = currAttr.Text


Set Nod = anXMLDoc.selectSingleNode(&quot;//Type&quot;)
Set Attr = Nod.Attributes.getNamedItem(&quot;VALUE&quot;)
var_for_Type = currAttr.Text

.....
 
I've managed to narrow this down to the code below. It iterates the correct number of times but the problem is that it only process the 1st parameter child tags in the loop. ie Docno is always the first doc no '123'.
and ideas/help will be greatly apreciated.:(

The initial table im working from looks like this
DocNo Type Day
123 A Mon
111 C Tue
333 D Wed


Set oList = mvarXMLDoc.selectNodes(&quot;//Parameter&quot;)

For Each currNode In oList
strDocNo = &quot;&quot;
strType = &quot;&quot;

Set currNode = anXMLDoc.selectSingleNode(&quot;//DocNo&quot;)
Set currAttr = currNode.Attributes.getNamedItem(&quot;VALUE&quot;)
strDocNo = currAttr.Text

Set currNode = mvarXMLDoc.selectSingleNode(&quot;//Type&quot;)
Set currAttr = currNode.Attributes(0)
strType = currAttr.Text
 
question: what are you using for your parser/source? is this client/server side?

i believe that in order to use getnameditem() you need to declare your node like this
<DocNo VALUE=&quot;123&quot;></DocNo>
if you are using a client side function that reads data from a node-set on the current page, or a server side function using the msxml parser (well i guess either one would probably use that parser)

other than that, the loop should be fine (if you want to use strDocNo and strType outside of the loop just use arrays of values)

here's a kind of similar example
mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
Thanks,Mike:)

Client side.

&quot;<DocNo VALUE=&quot;123&quot;></DocNo>&quot; was the missing link, this way docno now the node has an attribute i can point to.

<Parameters>
<Parameter DocNo=&quot;123&quot; Type=&quot;A&quot; Day=&quot;Mon&quot;/></Parameter>
<Parameter DocNo=&quot;111&quot; Type=&quot;C&quot; Day=&quot;Tue&quot;/></Parameter>
<Parameter DocNo=&quot;333&quot; Type=&quot;D&quot; Day=&quot;Wed&quot;/></Parameter>
</Parameters>

msgbox xmlstring

Set oList = anXMLDoc.selectNodes(&quot;//Parameters/Parameter&quot;)
mcnADO.BeginTrans

For Each currNode In oList

Set currAttr = currNode.Attributes.getNamedItem(&quot;DocNo&quot;)
If Not currAttr Is Nothing Then
strDocNo = currAttr.Text
End If

Set currAttr = currNode.Attributes.getNamedItem(&quot;Type&quot;)
If Not currAttr Is Nothing Then
strType = currAttr.Text
End If

update table...

mcnADO.Execute sSQL

next

mcnADO.CommitTrans

The wholee thing works correctly now except that it commits the transaction 3ce instead of once. i.e i c my msgbox 3ce
instead of once. I dont know if this is how &quot;mcnADO.CommitTrans&quot; works.
 
Thanks a lot ive figured it out.

the calling function was calling the function where update was taking place as many times as the loop....loop always equalled number of iterations on my msflexgrid (msflexgrid is where i was making my xmlstring from).


consider this problem/issue closed:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top