Results 1 to 6 of 6

Thread: [RESOLVED] Help with Xpath/VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    18

    Resolved [RESOLVED] Help with Xpath/VB6

    Not sure if I should be posting it here, or in the XML forum, but here goes;
    I need to parse and find certain records where the record name contains a certain string.
    For example, I have this XML:


    <B04_CALIPER>
    <AAIA_ID>1368109</AAIA_ID>
    <MODEL>A4 QUATTRO</MODEL>
    <Nameplate/>
    <Submodel/>
    <Appl>Caliper to Bracket</Appl>
    <FTorq>18</FTorq>
    <RTorq>22</RTorq>
    <Note/>
    </B04_CALIPER>

    <B06_LINING>
    <AAIA_ID>1368109</AAIA_ID>
    <Model_Name>A4 QUATTRO</Model_Name>
    <Nameplate/>
    <Submodel>STD Caliper</Submodel>
    <Loc>F</Loc>
    <Loc_Text>Front</Loc_Text>
    <MiniPad>.080</MiniPad>
    <MinShoe/>
    <NotP/>
    <NotS/>
    </B06_LINING>

    <B06_LINING>
    <AAIA_ID>1368109</AAIA_ID>
    <Model_Name>A4 QUATTRO</Model_Name>
    <Nameplate/>
    <Submodel/>
    <Loc>R</Loc>
    <Loc_Text>Rear</Loc_Text>
    <MiniPad>.276</MiniPad>
    <MinShoe/>
    <NotP>Includes backing plate. </NotP>
    <NotS/>
    </B06_LINING>
    -<B06_LINING>
    <AAIA_ID>1368109</AAIA_ID>
    <Model_Name>A4 QUATTRO</Model_Name>
    <Nameplate/>
    <Submodel>W/ Dual Piston</Submodel>
    <Loc>F</Loc>
    <Loc_Text>Front</Loc_Text>
    <MiniPad>.120</MiniPad>
    <MinShoe/>
    <NotP/>
    <NotS/>
    </B06_LINING>

    <B07_ROTOR>
    <AAIA_ID>1368109</AAIA_ID>
    <Model_Name>A4 QUATTRO</Model_Name>
    <Nameplate/>
    <Submodel/>
    <Pos>R</Pos>
    <Pos_Text>Rear</Pos_Text>
    <MaxPar>NS</MaxPar>
    <NotP/>
    <Runout>NS</Runout>
    <NotR/>
    <NomT>.390</NomT>
    <NotT/>
    <MinMach>NS</MinMach>
    <NotM/>
    <Discard>.310</Discard>
    <NotD/>
    <Finish>NS</Finish>
    <NotF/>
    </B07_ROTOR>

    How do I go about selecting all nodes that have the keyword LINING in the record name using XPATH?
    The only way I could figure out was to use the exact name which is B06_LINING, but I need to be able to search just by LINING. Any suggestions?

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help with Xpath/VB6



    Code:
    Option Explicit
    Private XMLdoc As MSXML2.DOMDocument40
    
    Private Sub Form_Load()
    
        Dim oxmlNodeList As IXMLDOMNodeList
        Dim lngIndex As Long
    
        Set XMLdoc = New DOMDocument40
        XMLdoc.async = False
        XMLdoc.validateOnParse = False
        XMLdoc.preserveWhiteSpace = False
        
        XMLdoc.Load "C:\temp\temp.xml"
        
        Set oxmlNodeList = XMLdoc.selectNodes("//*")
        For lngIndex = 0 To oxmlNodeList.length - 1
            If InStr(oxmlNodeList(lngIndex).baseName, "LINING") Then
                Debug.Print oxmlNodeList(lngIndex).baseName
            End If
        Next
         
     End Sub
    I'm also going to move this thread.

  3. #3

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    18

    Re: Help with Xpath/VB6

    Thanks, that was my next step, but I was looking for a way to pull them back with out looping through the entire document. This works just as well though, so thanks again.

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help with Xpath/VB6

    You're welcome and here is what you were looking for.

    Set oxmlNodeList = XMLdoc.selectNodes("//*[contains(name(),'LINING')]")

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    18

    Re: Help with Xpath/VB6

    Thanks again.

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