|
-
Jan 24th, 2009, 03:27 PM
#1
Thread Starter
Addicted Member
[02/03]
Ok gurus
I really need some help here
I have the following XML Doc.
Code:
<WC>
- <CMS>
<TYPE>PT</TYPE>
<DOC_NUM>472041</DOC_NUM>
<VENDOR_CODE>TX</VENDOR_CODE>
- <REVIEW>
<NUM>389518</NUM>
<DATE>20090110</DATE>
</REVIEW>
<BOOK_NUM>45203</BOOK_NUM>
<SUBTITLE_NUM />
<ORIG_TITLE_NUM />
<ORIG_SUBCLAIM_NUM />
<POLICY_NUM />
<JURISDICTION>TX</JURISDICTION>
<PRICING>TX</PRICING>
<LOSS_AMT>7100</LOSS_AMT>
<EXP_AMT>190</EXP_AMT>
<STATUS>FR</STATUS>
<DATE>20090119</DATE>
<TIME>110245</TIME>
<BY>RFC_USER</BY>
<REJ_REASON />
- <CHECK>
<NUM />
<ISSUE_DATE />
</CHECK>
<MESSAGE>not present.</MESSAGE>
I need to accomplish the following:
when TYPE =CH and STATUS=LI then I need to get the values of REVIEW NUM and also the value of CHECK->ISSUE_DATE
here is what I have so far that is not working very well
Code:
xmldoc = New Xml.XmlDocument
xmldoc.Load("c:\file.xml")
xnodelist = xmldoc.GetElementsByTagName("TYPE")
xnodelist2 = xmldoc.GetElementsByTagName("STATUS")
'xnodelist = xmldoc.DocumentElement.ChildNodes
For Each xnode1 In xnodelist
If xnode1.InnerText = "CH" Then
for each xnode2 in xnodelist2
if xnode2.innerText="LI" then
do something
next
End If
End If
next
I know is a mess , reason why I come to you for help.
Thanks
-
Jan 24th, 2009, 03:42 PM
#2
Re: [02/03]
Look into using XPath, it will let you query nodes, based on other nodes having specific values.
Here is a good link on how to learn Xpath.
http://www.w3schools.com/Xpath/
-
Jan 24th, 2009, 04:00 PM
#3
Thread Starter
Addicted Member
Re: [02/03] XML Help
N.
Thanks a bunch, is there any other way besides Xpath?
Thanks again
-
Jan 24th, 2009, 07:07 PM
#4
Re: [02/03]
try this:
vb Code:
Dim xmldoc As New Xml.XmlDocument
xmldoc.Load("c:\file.xml")
Dim type As String = xmldoc.SelectSingleNode("WC/CMS/TYPE").InnerText
Dim status As String = xmldoc.SelectSingleNode("WC/CMS/STATUS").InnerText
Dim reviewNum As String = String.Empty
Dim checkIssueDate As String = String.Empty
If type = "CH" And status = "LI" Then
reviewNum = xmldoc.SelectSingleNode("WC/CMS/REVIEW/NUM").InnerText
checkIssueDate = xmldoc.SelectSingleNode("WC/CMS/CHECK/ISSUE_DATE").InnerText
End If
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 24th, 2009, 10:13 PM
#5
Thread Starter
Addicted Member
Re: [02/03]
P.
Thanks for the replay but I have a question, I will have more than one record on my XML doc, so how can I loop the doc find the TYPE and STATUS and stay on that record to get the doc_NUM and the Check Issued_date and once this is done get to the next recod and loop for the same thing.
Thanks
-
Jan 25th, 2009, 08:12 AM
#6
Re: [02/03]
try this:
vb Code:
Dim xmldoc As New Xml.XmlDocument
xmldoc.Load("c:\file.xml")
Dim nodes As Xml.XmlNodeList = xmldoc.SelectNodes("WC/CMS")
Dim type(nodes.Count - 1) As String
Dim status(nodes.Count - 1) As String
Dim reviewNum(nodes.Count - 1) As String
Dim checkIssueDate(nodes.Count - 1) As String
For x As Integer = 0 To nodes.Count - 1
type(x) = nodes(x).SelectSingleNode("TYPE").InnerText
status(x) = nodes(x).SelectSingleNode("STATUS").InnerText
If type(x) = "CH" And status(x) = "LI" Then
reviewNum(x) = nodes(x).SelectSingleNode("REVIEW/NUM").InnerText
checkIssueDate(x) = nodes(x).SelectSingleNode("CHECK/ISSUE_DATE").InnerText
End If
Next
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 25th, 2009, 10:44 AM
#7
Thread Starter
Addicted Member
Re: [02/03]RESOLVED
WOW!!!!!!!!!!!!!!!!!!!!!!!!!!!
P. Thanks a bunch, Thanks everyone for their imput on this thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|