Micro Focus QTP (UFT) Forums
XML Parsing Problem ..Any suggestions - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: XML Parsing Problem ..Any suggestions (/Thread-XML-Parsing-Problem-Any-suggestions)



XML Parsing Problem ..Any suggestions - Reed - 08-02-2011

iterating through the xml message works great when the results all have the same number of nodes but what do I do when a node is missing. For Ex. When I ask it to get the LastName value for PlayerID 17486 it grabs it from the next player (84636). I'd like it to be return the correct values within the PlayerFound tag.

Code:
Set nodes = xmlDoc.SelectNodes("/bookstore/book/title/text()")
' get their values
For i = 0 To (nodes.Length - 1)
    Title = nodes(i).NodeValue
    MsgBox "Title #" & (i + 1) & ": " & Title
Next

Set xmlPlayerID = xmlDoc.SelectNodes("CRMAcresMessage/Body/PlayerFind2/PlayersFound/PlayerFound/PlayerID/text()")
Set xmlFirstName = xmlDoc.SelectNodes("CRMAcresMessage/Body/PlayerFind2/PlayersFound/PlayerFound/FirstName/text()")
Set xmlLastName = xmlDoc.SelectNodes("CRMAcresMessage/Body/PlayerFind2/PlayersFound/PlayerFound/LastName/text()")
Set xmlPreferredName = xmlDoc.SelectNodes("CRMAcresMessage/Body/PlayerFind2/PlayersFound/PlayerFound/PreferredName/text()")
Set xmlRanking = xmlDoc.SelectNodes("CRMAcresMessage/Body/PlayerFind2/PlayersFound/PlayerFound/Ranking/text()")
Set xmlCreditAccount = xmlDoc.SelectNodes("CRMAcresMessage/Body/PlayerFind2/PlayersFound/PlayerFound/CreditAccount/text()")

<PlayerFound>
<PlayerID>84636</PlayerID>
<LastName>ACOSTA</LastName>
<FirstName>MATEO</FirstName>
<PreferredName>MATEO</PreferredName>
<CreditAccount>No</CreditAccount>
<Ranking>Level 1</Ranking>
</PlayerFound>

<PlayerFound>
<PlayerID>84642</PlayerID>
<LastName>ACOSTA</LastName>
<FirstName>MAURICIO</FirstName>
<PreferredName>MAURICIO</PreferredName>
<CreditAccount>No</CreditAccount>
<Ranking>Level 1</Ranking>
</PlayerFound>