Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Extracting Data from XML

$
0
0

It has been a long time since I have posted here, but I'm stuck on a powershell/xml question.

I've written a powershell script that reads in a lot of data from some cmdlets and generates an XML document.  (As an aside, Dr. Weltner's amazing article on creating these XML files was my bible for this! http://www.powershellmagazine.com/2013/08/19/mastering-everyday-xml-tasks-in-powershell/). 

The key issue is that I have a layout similar to this:

<Applications>

<AppName#1>

<PropertyElement>SomePropertyHere</PropertyElement>

<User>username</user>

<User>username2</user>

<groupuser>username3</groupuser>

<groupuser>username4</groupuser>

</AppName#1>

<AppName#2>

<PropertyElement>SomePropertyHere</PropertyElement>

<User>username</user>

<User>username5</user>

<groupuser>username3</groupuser>

<groupuser>username6</groupuser>

</AppName#2>

</Applications>

Now that I have a complete XML file with all the data I could want, I want to be able to extract subsections to create dynamic reports based on this data.

What I need to do is extract the data in powershell, and then create the HTML part.  I've got most of the HTML handling down, but the extraction of the data is where I am stuck.  Each app can have a variable number of users (0 to however many) and same with the group users.. there could be anywhere from 0 to unlimited).  

Ultimately, my HTML table will look like this (minus the pretty formatting)

Application Name    | Users                               | Group Users
------------------------------------------------------------------------------------------
Application#1         | username, username2     | username3, username4
Application#2         | username, username5     | username3, username6

I am just not sure how to get those user elements and build a string out of them to insert into my HTML.  (The string building & html conversion are easy.. it's the extraction of multiple elements of the same name from multiple applications that are all in a nested tree structure).
Thanks for any help provided!
David Figueroa

Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images