Results 1 to 7 of 7

Thread: [02/03]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    [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

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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/

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: [02/03] XML Help

    N.

    Thanks a bunch, is there any other way besides Xpath?

    Thanks again

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [02/03]

    try this:

    vb Code:
    1. Dim xmldoc As New Xml.XmlDocument
    2. xmldoc.Load("c:\file.xml")
    3.  
    4.  
    5. Dim type As String = xmldoc.SelectSingleNode("WC/CMS/TYPE").InnerText
    6. Dim status As String = xmldoc.SelectSingleNode("WC/CMS/STATUS").InnerText
    7.  
    8. Dim reviewNum As String = String.Empty
    9. Dim checkIssueDate As String = String.Empty
    10.  
    11. If type = "CH" And status = "LI" Then
    12.     reviewNum = xmldoc.SelectSingleNode("WC/CMS/REVIEW/NUM").InnerText
    13.     checkIssueDate = xmldoc.SelectSingleNode("WC/CMS/CHECK/ISSUE_DATE").InnerText
    14. End If

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    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

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [02/03]

    try this:

    vb Code:
    1. Dim xmldoc As New Xml.XmlDocument
    2. xmldoc.Load("c:\file.xml")
    3.  
    4. Dim nodes As Xml.XmlNodeList = xmldoc.SelectNodes("WC/CMS")
    5.  
    6. Dim type(nodes.Count - 1) As String
    7. Dim status(nodes.Count - 1) As String
    8. Dim reviewNum(nodes.Count - 1) As String
    9. Dim checkIssueDate(nodes.Count - 1) As String
    10.  
    11. For x As Integer = 0 To nodes.Count - 1
    12.     type(x) = nodes(x).SelectSingleNode("TYPE").InnerText
    13.     status(x) = nodes(x).SelectSingleNode("STATUS").InnerText
    14.     If type(x) = "CH" And status(x) = "LI" Then
    15.         reviewNum(x) = nodes(x).SelectSingleNode("REVIEW/NUM").InnerText
    16.         checkIssueDate(x) = nodes(x).SelectSingleNode("CHECK/ISSUE_DATE").InnerText
    17.     End If
    18. Next

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    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
  •  



Click Here to Expand Forum to Full Width