0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="MultipleSuite">
<suite-files>
    <suite-file path="samplexml_1.xml"></suite-file>
</suite-files>
</suite>
<!-- Suite -->

here how to get the 'samplexml_1.xml' name ?

3 Answers 3

1

Use XPath and the Select-Xml cmdlet:

$suite_file = Select-Xml "//suite-file" yourfile.xml

This selects an array of <suite-file> nodes (in your example, there is only one match). You can access the result like this:

$suite_file.Node.path

prints

samplexml_1.xml
Sign up to request clarification or add additional context in comments.

Comments

0

Get content of xml file to [xml] type variable. Like so:

[xml]$xml = Get-Content file.xml
$xml.suite.'suite-files'.'suite-file'.path
#samplexml_1.xml

1 Comment

Don't do [xml]$xml = Get-Content file.xml. This will break the data when the file is not in the encoding Get-Content expects. $xml = New-Object xml; $xml.Load("file.xml") is much better, because this uses the encoding detection of the XML parser.
0

This would work but is probably not the best solution depending on what you want to achieve at the end.

$xml = [xml]'<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="MultipleSuite">
<suite-files>
    <suite-file path="samplexml_1.xml"></suite-file>
</suite-files>
</suite>'

$xml.suite."suite-files"."suite-file".path

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.