parse xml value to variable

shubham jain 0 Reputation points
2023-09-12T17:58:10.9366667+00:00

Hello,

I want to pass the value to total test case and failures as variable from my xml file. Please help me with poweshell script.

xml file code-

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="QIS - Smoke Testing Automation Script.Smoke Test Suite" time="113.132" tests="24" failures="0" errors="0" package="QIS - Smoke Testing Automation Script" id="1">
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,527 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 46,796 Reputation points
    2023-09-13T01:48:52.0033333+00:00

    Your XML, as posted, isn't usable. Please don't fail to verify that the data you post is in usable format.

    Is a simple case such as this, this should be all you need:

    $xml = @"
    <?xml version="1.0" encoding="UTF-8"?>
    <testsuites>
      <testsuite name="QIS - Smoke Testing Automation Script.Smoke Test Suite" time="113.132" tests="24" failures="0" errors="0" package="QIS - Smoke Testing Automation Script" id="1">
      </testsuite>
    </testsuites>
    "@
    $x = [xml]$xml
    $x.testsuites.testsuite.tests
    $x.testsuites.testsuite.failures
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.