Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

XML File Parsing atrributes (my code seems odd)

$
0
0
Hey I'm working on this tool that retrieves certain things from an xml file in this structure
UserCFG.xml

Code:

<?xml version="1.0" ?>
<graphic>
    <adapter vendorid="32902" productid="358" description="Intel(R) HD Graphics 4000" adapterid="MONITOR\CMO1720\{4d36e96e-e325-11ce-bfc1-08002be10318}\0001" name="\\.\DISPLAY1" guid="d7b78e66-4226-11cf-b177-0e01b4c2c435" />
    <resolution width="1920" height="1080" refresh="60" />
    <options aa="0" vsync="1" windowed="0" motionblur="0" ssao="2" shadow="2" reflection="0" inversion="0" control_layout="0" vibration="1" fov_norm="38" fov_aim="26" volume="100" voice_language="0" />
</graphic>


To do this I coded this, but I feel it's very wrong and there must be a better way to do it

Code:

        Dim primetime As String = TextBox1.Text
        Dim vendorid As String = "undefined"
        Dim productID As String = "undefined"
        Dim doc As XDocument = XDocument.Load(primetime)


        Dim labels_v() As String = _
        (From label In doc.Root.<adapter>.Attributes("vendorid") _
        Select CType(label, String)).ToArray()


        Dim labels_p() As String = _
        (From label In doc.Root.<adapter>.Attributes("productid") _
        Select CType(label, String)).ToArray()


        For Each label As String In labels_v
            vendorid = label
        Next

        For Each labelz As String In labels_p
            productID = labelz
        Next


        MsgBox("Vendor id is : " & vendorid)
        MsgBox("Product ID is : " & productID)


SO it outputs the vendor ID and product ID. Can someone brush up on my work or is this good enough.

Thanks

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>