Hello friends
I would love to have your help with a blocking for hours.
In summary, I have to read an XML file and retrieve information with the VB.Net language.
I would like to recover the "name", the "checkvalue" and the "compositekey"
That's the structure of my xml file:
<supercollection name="BF000000.hks"> <collections> <collection maxdukptkeyindex="17" maxmskeyindex="13" merchantid="" applicationcertificate="Only Collection Certificate" applicationname="Only Collection Application" name="Only Collection"> <mskeys> <key index="1" checkvalue="E8F71A" variantindex="0" verifycheckvalue="yes" keylength="32" compositekey="BA03BDBDF091092C26B9D22A2922F504" usage="1" encryptionmode="TECB" name="Key"> <type>Master</type> </key> </mskeys> <dukptkeys></dukptkeys> </collection> </collections> </supercollection>

I've never had much luck working with XML and I'm sure there is a better way to do this via Linq but you could try a regular expression approace as in

Private Function GetField(name As String) As String

    Dim pattern = name & "=""(.*?)"""
    Dim rex = New Regex(pattern)
    Dim match = rex.Matches(txtXML.Text)

    Try
        Return match(0).Groups(1).Value
    Catch ex As Exception
        Return "not found"
    End Try

End Function

Pass it a field name like "supercollection name" (case sensitive) and it will return a field value as a string. If you want someone to post a Linq solution you'll have to post a complete xml sample document.

commented: This is my story. Client hands me XML, Microsoft XMLreader blows up. I parse it with my own code. +15

Here is what the contents of my xml file look like

<supercollection name="BF000000.hks">
    <collections>
        <collection maxdukptkeyindex="17" maxmskeyindex="13" merchantid="" applicationcertificate="Only Collection Certificate" applicationname="Only Collection Application" name="Only Collection">
            <mskeys>
                <key index="1" checkvalue="E8F71A" variantindex="0" verifycheckvalue="yes" keylength="32" compositekey="BA03BDBDF091092C26B9D22A2922F504" usage="1" encryptionmode="TECB" name="Key">
                    <type>Master</type>
                </key>
            </mskeys>
            <dukptkeys/>
        </collection>
    </collections>
</supercollection>

Dang. I always complain when other people do this and now I did it. I left out the import when I posted the code. Please add the following:

Imports System.Text.RegularExpressions

I'll see if I can figure out the Linq version. I'll post it later if I have any luck.

commented: Thank you for your help with this function but it returns me not found +0

Please someone wants to help me solve this blocking problem.
I would like to recover the following values with VB.Net: name, checkvalue and compositekey

I posted code that will do that. It's the only solution you have so far so use it until something better comes along. I tested it with the xml text that you provided, and requesting the fields you specified. I loaded the test data with

txtXML.Text = My.Computer.FileSystem.ReadAllText("D:\test.xml")

2019-06-26_111457.jpg

2019-06-26_111253.jpg

2019-06-26_111309.jpg

commented: thank you very much it works well with your function +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.