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

How To XMLReader Parse SubNode 1

Status
Not open for further replies.

RRAnthon

Programmer
Sep 25, 2005
24
US
I'm using XMLReader, so far so good. However, my problem is I need to parse out a subnode and cannot figure out how to use the XMLReader to do that.

My code:

If xtr.Name = "Quote_Coverage" Then
xtr.MoveToAttribute("Quote_Coverage_Id")
xml_MessageArray.Quote_Coverage_Id = xtr.Value
xtr.MoveToAttribute("Plan_Name")
xml_MessageArray.Plan_Name = xtr.Value
If xtr.Name = "Benefits" Then
xtr.MoveToAttribute("SubCategory")
xml_MessageArray.SubCategory = xtr.Value
xtr.MoveToAttribute("Code")
xml_MessageArray.Code = Replace(xtr.Value, "/", "_")
End If
end if

I'm trying to get the attributes from the child node Benefits, but since it's at the element Quote-Coverage all it wants to read is all of those first. I'd like to load an array or something similar for each iteration.

My xml:

<Quote_Coverages>
- <Quote_Coverage Quote_Coverage_Id="094F" Plan_Name="Plan_A">
- <Benefits>
<Benefit SubCategory="Small Group Pharmacy" Code="SG123" />
</Benefits>
</Quote_Coverage>
- <Quote_Coverage Quote_Coverage_Id="094G" Plan_Name="Plan_B">
- <Benefits>
<Benefit SubCategory="Small Group Medical" Code="SG456" />
</Benefits>
</Quote_Coverage
 
It would look something like this.
[tt]
'xtr got initiated and pointed to the uri
[blue]While xtr.MoveToFollowing("Quote_Coverage")[/blue]
xtr.MoveToAttribute("Quote_Coverage_Id")
xml_MessageArray.Quote_Coverage_Id = xtr.Value
xtr.MoveToAttribute("Plan_Name")
xml_MessageArray.Plan_Name = xtr.Value
[red]xtr.MoveToElement()[/red]
[blue]While xtr.ReadToDescendant("Benefit")[/blue]
xtr.MoveToAttribute("SubCategory")
xml_MessageArray.SubCategory = xtr.Value
xtr.MoveToAttribute("Code")
xml_MessageArray.Code = Replace(xtr.Value, "/", "_")
[red]xtr.MoveToElement()[/red]
[blue]End While[/blue]
[blue]End While[/blue]
[/tt]
 
Amendment
A typo here: the corresponding line should be read like this.
>[self]While xtr.MoveToFollowing("Quote_Coverage")
[tt]While xtr.[red]Read[/red]ToFollowing("Quote_Coverage")
[/tt]
 
Thanks for that, I can't wait to get in and try this. I'll let you know.
 
Score! Thanks tsuji, that did the trick. Only had one glitch, which was I needed to preface the while with the parent element:

If xtr.Name "Quote_Coverages" then
then the readtofollowing "Quote_Coverage" and the rest worked perfectly.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top