Parsing HTML in vb.net RRS feed

  • Question

  • Hello,

    I currently write an app which determines the remaining life span of the notebook battery. I also want to publish this app in the Windows Store. My app calls the Windows command "powercfg.exe /batteryreport" to get the status data of the battery. Powercfg.exe creates an HTML file and my app gets the data from this file.

    I wrote a simple HTML parser to read the HTML file generated by Powercfg.exe (using for/next) - but it´s very slow. Is there a better and faster way to parse an HTML file in Visual Basic .net? Or is there a way to find a specific string directly? I use .net Framework 4.6.2.

    Thank you.



    Friday, July 24, 2020 9:07 AM

All replies

  • There is a package that will do this for you


    Lloyd Sheen

    Friday, July 24, 2020 11:25 AM
  • Maybe it is easier to add the /XML option to powercfg command. Then you can use XmlDocument, XDocument, XPath, LINQ to XML.

    For example:

    Imports <xmlns:ns="http://schemas.microsoft.com/battery/2012">

    . . .

    Dim xdoc As XDocument = XDocument.Load("battery-report.xml")

    Dim battery_manufacturer As String = xdoc.<ns:BatteryReport>.<ns:Batteries>.<ns:Battery>.<ns:Manufacturer>.Value

    Friday, July 24, 2020 11:29 AM
  • Thanks for your tips! I managed now to make my HTML parser faster using the InStr function of vb.net.

    Works great! :-)

    Friday, July 24, 2020 5:48 PM
  • Hi Karsten1976,

    If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 27, 2020 8:52 AM